ssm框架的搭建實現CRUD的操做

 

 

最近在開發公司的一個系統,系統的框架是用ssm的框架搭建的,固然和此次寫博客的不同,它擁有不少的配置文件,企業級的開發所須要的配置文件是很是繁瑣的,今天記錄一下一個簡單的SSM框架的搭建和實現一個CRUD的操做。javascript

 

使用的是Maven插件來配置咱們須要的jar包,因爲操做很少,因此並無配置不少,要注意本身使用的jdk的版本,選擇不一樣版本號的jdkhtml

複製代碼
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.lr</groupId>
  <artifactId>ssm</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>ssm Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <!-- 用來設置版本號 -->  
    <properties>  
        <srping.version>4.0.2.RELEASE</srping.version>  
        <mybatis.version>3.2.8</mybatis.version>  
        <slf4j.version>1.7.12</slf4j.version>  
        <log4j.version>1.2.17</log4j.version>  
    </properties>  
    <!-- 用到的jar包 -->  
    <dependencies>  
        <!-- 單元測試 -->  
        <dependency>  
            <groupId>junit</groupId>  
            <artifactId>junit</artifactId>  
            <version>4.11</version>  
            <!-- 表示開發的時候引入,發佈的時候不會加載此包 -->  
            <scope>test</scope>  
        </dependency>  
        <!-- java ee包 -->  
        <dependency>  
            <groupId>javax</groupId>  
            <artifactId>javaee-api</artifactId>  
            <version>7.0</version>  
        </dependency>  
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.8</version>
        </dependency>
        
        <!-- spring框架包 start -->  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-test</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-core</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-oxm</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-tx</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-jdbc</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-aop</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context-support</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-expression</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-orm</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-web</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-webmvc</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-aspects</artifactId>  
            <version>${srping.version}</version>  
        </dependency>  
        <!-- spring框架包 end -->  
        <!-- mybatis框架包 start -->  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis</artifactId>  
            <version>${mybatis.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.mybatis</groupId>  
            <artifactId>mybatis-spring</artifactId>  
            <version>1.2.2</version>  
        </dependency>  
        <!-- mybatis框架包 end -->  
        <!-- 數據庫驅動 -->  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
            <version>5.1.35</version>  
        </dependency>  
        <!-- 導入dbcp的jar包,用來在applicationContext.xml中配置數據庫 -->  
        <dependency>  
            <groupId>commons-dbcp</groupId>  
            <artifactId>commons-dbcp</artifactId>  
            <version>1.4</version>  
        </dependency>  
        <!-- jstl標籤類 -->  
        <dependency>  
            <groupId>jstl</groupId>  
            <artifactId>jstl</artifactId>  
            <version>1.2</version>  
        </dependency>  
        <dependency>  
            <groupId>taglibs</groupId>  
            <artifactId>standard</artifactId>  
            <version>1.1.2</version>  
        </dependency>  
        <!-- log start -->  
        <dependency>  
            <groupId>log4j</groupId>  
            <artifactId>log4j</artifactId>  
            <version>${log4j.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-api</artifactId>  
            <version>${slf4j.version}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.slf4j</groupId>  
            <artifactId>slf4j-log4j12</artifactId>  
            <version>${slf4j.version}</version>  
        </dependency>  
        <!-- log END -->  
        <!-- Json -->  
        <!-- 格式化對象,方便輸出日誌 -->  
        <dependency>  
            <groupId>com.alibaba</groupId>  
            <artifactId>fastjson</artifactId>  
            <version>1.2.6</version>  
        </dependency>  
        <dependency>  
            <groupId>org.codehaus.jackson</groupId>  
            <artifactId>jackson-mapper-asl</artifactId>  
            <version>1.9.13</version>  
        </dependency>  
        <!-- 上傳組件包 start -->  
        <dependency>  
            <groupId>commons-fileupload</groupId>  
            <artifactId>commons-fileupload</artifactId>  
            <version>1.3.1</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-io</groupId>  
            <artifactId>commons-io</artifactId>  
            <version>2.4</version>  
        </dependency>  
        <dependency>  
            <groupId>commons-codec</groupId>  
            <artifactId>commons-codec</artifactId>  
            <version>1.10</version>  
        </dependency>  
        <!-- 上傳組件包 end -->  
  
        <!-- AL相關添加 -->  
        <dependency>  
            <groupId>net.sourceforge.jexcelapi</groupId>  
            <artifactId>jxl</artifactId>  
            <version>2.6</version>  
        </dependency>  
        <dependency>  
            <groupId>org.apache.poi</groupId>  
            <artifactId>poi</artifactId>  
            <version>3.8</version>  
        </dependency>  
        <dependency>  
            <groupId>org.apache.poi</groupId>  
            <artifactId>poi-ooxml</artifactId>  
            <version>3.9</version>  
        </dependency>  
        <!-- AL相關添加 -->  
    </dependencies>  
  
     <build>  
        <finalName>Maven_Project</finalName>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>2.3.2</version>  
                <configuration>  
                    <source>1.7</source>  
                    <target>1.7</target>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>   
</project>  
複製代碼

而後配置數據庫的鏈接,改爲本身的數據庫就好了前端

複製代碼
driver=com.mysql.jdbc.Driver
url=jdbc\:mysql\://locahost\:3306/db
username=root
password=root
maxActive=20
maxIdle=20
minIdle=1
maxWait=60000
複製代碼

配置文件spring-dao.xml,Spring會自動查找其下的類java

複製代碼
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd    
                        http://www.springframework.org/schema/mvc    
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
                          
                          
    <!-- DAO接口所在包名,Spring會自動查找其下的類 -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <!--basePackage指定要掃描的包,在此包之下的映射器都會被搜索到。  
         可指定多個包,包與包之間用逗號或分號分隔-->  
        <property name="basePackage" value="com.lr.dao" />  
        <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>  
    </bean>                         
                          
</beans>  
複製代碼

配置文件Spring和Mybatis的整合文件mysql

複製代碼
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd    
                        http://www.springframework.org/schema/mvc    
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
  
    <!-- 引入配置文件 -->  
<context:property-placeholder location="classpath:/jdbc.properties" />
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/db?useUnicode=true&amp;characterEncoding=utf8" />
        <property name="username" value="root" />
        <property name="password" value="root" />
        <!-- 初始化鏈接大小 -->
        <property name="initialSize" value="3" />  
        <!-- 鏈接池最大數量 -->
        <property name="maxActive" value="20" />
        <!-- 鏈接池最大空閒 -->
        <property name="maxIdle" value="20" />
        <!-- 鏈接池最小空閒 -->  
        <property name="minIdle" value="1" />
        <!-- 獲取鏈接最大等待時間 -->  
        <property name="maxWait" value="60000" />
    </bean>  
  
    <!-- spring和MyBatis完美整合,不須要mybatis的配置映射文件 -->  
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <!-- 自動掃描mapping.xml文件 -->  
        <property name="mapperLocations" value="classpath:com/lr/mapper/*.xml"></property>  
    </bean>  
      
</beans>  
複製代碼

配置事物的文件jquery

複製代碼
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:aop="http://www.springframework.org/schema/aop"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd    
                        http://www.springframework.org/schema/aop   
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
                        http://www.springframework.org/schema/tx  
                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">  
  
    <!-- (事務管理)transaction manager, use JtaTransactionManager for global tx -->  
    <bean id="transactionManager"  
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
      
     <!--  配置參與事務的類 -->  
     <aop:config>  
         <aop:pointcut id="allServiceMethod" expression="execution(* com.lr.service.*.*(..))"/>  
         <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />  
     </aop:config>  
      
    <!-- 使用聲明方式配置事務 -->  
    <tx:advice id="txAdvice" transaction-manager="transactionManager">  
         <tx:attributes>  
               <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>  
         </tx:attributes>  
    </tx:advice>  
      
</beans>  
複製代碼

配置Springmvc.xml文件web

複製代碼
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
                        http://www.springframework.org/schema/context    
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd    
                        http://www.springframework.org/schema/mvc    
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
      
    <!-- 自動掃描 -->  
    <context:component-scan base-package="com.lr.controller" />  
      
    <mvc:annotation-driven />  
    
    <mvc:default-servlet-handler/>
    
    <!-- 定義跳轉的文件的先後綴 ,視圖模式配置-->  
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
       
        <property name="prefix" value="/WEB-INF/jsp/" />  
        <property name="suffix" value=".jsp" />  
    </bean>  
      
  
複製代碼

好了!!!須要配置的文件已經配置完成了,足夠咱們進行一波操做了ajax

接下來是後臺的一些代碼,這裏主要是實體類,dao層,service層,controller層,我把後臺的文件一塊兒上傳了,mapper.xml文件是實現方法最關鍵的地方spring

按 Ctrl+C 複製代碼
按 Ctrl+C 複製代碼
複製代碼
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >  
<mapper namespace="com.lr.dao.IUserDao">
    <resultMap id="BaseResultMap" type="com.lr.dto.User">
        <result column="id" property="id" jdbcType="INTEGER" />  
        <result column="name" property="name" jdbcType="VARCHAR" />  
        <result column="password" property="password" jdbcType="VARCHAR" />  
        <result column="age" property="age" jdbcType="INTEGER" /> 
    </resultMap>
    
    <sql id="Base_Column_List">  
        id, name, password, age  
    </sql>  
    
    
      <!--   增長用戶 -->
      <insert id="addUser" parameterType="com.lr.dto.User">
        insert into user(name,password,age) values(#{name},#{password},#{age})
    </insert>
    
     <!-- 查詢用戶-->  
    <select id="queryByPrimaryKey" resultMap="BaseResultMap"  
        parameterType="java.lang.Integer">  
        select  
        <include refid="Base_Column_List" />  
        from user  
        where id = #{id}  
    </select>  
    
    
     <!-- 刪除用戶 -->  
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">  
        delete from user  
        where id = #{id}    
    </delete>  
    
    
    <!-- 更新用戶 -->  
    <update id="updateByPrimaryKey" parameterType="com.lr.dto.User" >    
        update user set name=#{name},password=#{password},age=#{age} where id=#{id}
    </update>  
    
    <select id="findallUser" resultType="com.lr.dto.User">
        select * from user
    </select>
    
</mapper>
複製代碼
複製代碼
package com.lr.dao;

import java.util.List;

import com.lr.dto.User;

public interface IUserDao {
     //查詢用戶  
    public User queryByPrimaryKey(int id);  
     //刪除用戶  
    public int deleteByPrimaryKey(int id);  
    //更新用戶
    public int updateByPrimaryKey(User user);
    //添加用戶
    public int addUser(User user);
    //查詢全部用戶
    public List<User> findallUser();
}
複製代碼
複製代碼
package com.lr.service;

import java.util.List;

import com.lr.dto.User;

public interface IUserService {
    //查詢用戶  
     public User getUserById(int userId);
     //刪除
     public void deleteUser(int id);
     //更新用戶
     public void updateUser(User user);
    //添加用戶
     public void addUser(User user);
     //查看全部用戶
     public List<User> findallUser();
}
複製代碼
複製代碼
package com.lr.service.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lr.dao.IUserDao;
import com.lr.dto.User;
import com.lr.service.IUserService;
@Service("userService")
public class UserServiceImpl implements IUserService{
    @Resource
    private IUserDao userdao;
    
    public IUserDao getUserdao() {
        return userdao;
    }
    public void setUserdao(IUserDao userdao) {
        this.userdao = userdao;
    }
    //查詢用戶
    @Override
    public User getUserById(int userId) {
        
        return userdao.queryByPrimaryKey(userId);
    }
    //更新用戶
    @Override
    public void updateUser(User user) {
        userdao.updateByPrimaryKey(user);
        
    }
    //刪除用戶
    @Override
    public void deleteUser(int id) {
        
        userdao.deleteByPrimaryKey(id);
    }
    
    //添加用戶
    @Override
    public void addUser(User user) {
        
        userdao.addUser(user);
    }
    
    //查詢全部用戶
    @Override
    public List<User> findallUser() {
        
        return userdao.findallUser();
    }
}
複製代碼
複製代碼
package com.lr.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lr.dto.User;
import com.lr.service.IUserService;

@Controller
public class UserController {
    @Autowired
    private IUserService userService;
    
    public IUserService getUserService() {
        return userService;
    }
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }  
    
    //主頁面
    @RequestMapping("/")
    public String userMgr() {
        return "showUser";
    }
    
    //添加用戶
    @RequestMapping("/addUser")
    @ResponseBody
    public void userAdd(User user) {
        userService.addUser(user);
    }
    
    //刪除用戶
    @RequestMapping("/deleteUser")
    @ResponseBody
    public void deleteUser(int id){
        userService.deleteUser(id);
    }
    
    //修改用戶
    @RequestMapping("/updateUser")
    @ResponseBody
    public void upadteUser(User user){
        
        userService.updateUser(user);
        
    }
    //根據id查找用戶
    @RequestMapping("/showUser")  
    @ResponseBody
    public User showUser(int id,Model model){  
         return userService.getUserById(id);         
    }
    
    //查詢全部用戶
    @RequestMapping("/findallUser")
    @ResponseBody
    public List<User> findallUser(){
        return userService.findallUser();
    }
}
複製代碼

最後是前端,由於隨便寫的,前端有些low,請不要針對我胖虎!!!!!sql

複製代碼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
  <head>    
    <meta charset="utf-8"><script type="text/javascript" src="<%= application.getContextPath() %>/js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
    
    
    
    //添加用戶
        $(function(){
            $("#add").on("click", addNewUser);        
        })
        function addNewUser(){
            var name = $.trim($("#txtName").val());
            var password = $.trim($("#txtPassword").val());
            var age = $.trim($("#txtAge").val());
            
            $.post("/ssm/addUser", {"name": name, "password": password, "age": age}, function(){
                alert("添加成功!")
            });
        }
        
        
        
    //刪除用戶
        $(function(){
            $("#delete").on("click",deleteUser);
        })
        function deleteUser(){
            var id=$.trim($("#deleteid").val());
            $.get("/ssm/deleteUser",{"id":id},function(){
                alert("刪除成功!")
            });
        }
        
        
    //查詢全部用戶
        $(function(){
            $("#findalluser").click(function(){
                $.ajax({
                    type:"POST",
                    dataType:"json",
                    url:"/ssm/findallUser",
                    success:function(msg){
                        var str="";
                        for(i in msg){
                            str+="<tr><th>"+msg[i].id+"</th><th>"+msg[i].name+"</th><th>"
                            +msg[i].password+"</th><th>"+msg[i].age+"</th><tr>"
                        }
                        $("#findall").append(str);
                    }
                });
            });
        });
        
        
        //根據id查找一個用戶
        
        $(function(){
            $("#find").click(function(){
                $.ajax({
                    type:"POST",
                    data:{id:$("#findid").val()},
                    dataType:"json",
                    url:"/ssm/showUser",
                    success:function(user){
                        var str="";
                            str+="<tr><th>"+user.id+"</th><th>"+user.name+"</th><th>"
                            +user.password+"</th><th>"+user.age+"</th><tr>"
                        $("#finduserbyid").append(str);
                    }
                    
                })
            })
        })
        
        
        //根據id修改用戶信息
        $(function(){
            $("#update").on("click",updateUser);
        })
        function updateUser(){
             alert($.trim($("#updateid").val()))
            alert($.trim($("#updatename").val()))
            alert($.trim($("#updatepassword").val()))
            alert($.trim($("#updateage").val())) 
        
            var id=$.trim($("#updateid").val());
            var name=$.trim($("#updatename").val());
            var password=$.trim($("#updatepassword").val());
            var age=$.trim($("#updateage").val());
            $.post("/ssm/updateUser",{"id":id,"name":name,"password":password,"age":age},function(){
                alert("修改爲功!")
            });
        }
    </script>
    
    
  <title>用戶管理</title>   
  </head>
  <body>
    <div>
        <p>姓名:<input type="text" id="txtName"></p>
        <p>密碼:<input type="password" id="txtPassword"></p>
        <p>年齡:<input type="text" id="txtAge"></p>
        <p><button id="add">添加</button></p>
    </div>
    <hr style="height:1px;border:none;border-top:1px dashed #0066CC;" />
    
    <div>
        <p>輸入用戶id:<input type="text" id="deleteid"></p>
        <p><button id="delete">刪除</button></p>
    </div>
    
    <hr style="height:1px;border:none;border-top:1px dashed #0066CC;" />
    
    <div><p><button id="findalluser">查詢全部</button></p></div>
    <div>
        <table width="300" border="1" >
            <thead id="findall">
                <tr>
                    <th width="50">id</th>
                    <th width="50">姓名</th>
                    <th width="50">密碼</th>
                    <th width="50">年齡</th>
                </tr>
            </thead>
        </table>
    </div>
    <hr style="height:1px;border:none;border-top:1px dashed #0066CC;" />
    
    <div>
        <p>輸入用戶id:<input type="text" id="findid"></p>
        <p><button id="find">查詢</button></p>
    </div>
     <div>
        <table width="300" border="1" >
            <thead id="finduserbyid">
                <tr>
                    <th width="50">id</th>
                    <th width="50">姓名</th>
                    <th width="50">密碼</th>
                    <th width="50">年齡</th>
                </tr>
            </thead>
        </table>
    </div>
    <hr style="height:1px;border:none;border-top:1px dashed #0066CC;" />
    
    
    <div>
        <p>輸入用戶id:<input type="text" id="updateid"></p>
        <p>輸入用戶姓名:<input type="text" id="updatename"></p>
        <p>輸入密碼:<input type="password" id="updatepassword"></p>
        <p>輸入用戶年齡:<input type="password" id="updateage"></p>
        <p><button id="update">修改</button></p>
    </div>
  </body>
</html>
複製代碼

好了!!!到此爲止一個簡單的SSM框架就搭建完成了,實現了一個簡單的CRUD的功能,有很是多的擴展功能,須要咱們一步一步的去開發

相關文章
相關標籤/搜索