使用maven,实现ssm(spring+springmvc+mybatis)三大框架的整合DEMO

刚进一家新公司,要求使用ssm三大框架,而且这个组合是现在的主流,所以在整合的同时将步骤一步一步记录下来,方便以后的再次使用。
1.首先是建立一个Maven-project,具体操作请参考我的另一篇文章 点击这里 
2. 然后导入maven依赖,这里将我的依赖列出如下
[html] view plain copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0modelVersion>  
  4.     <groupId>org.bbgroupId>  
  5.     <artifactId>ssmartifactId>  
  6.     <packaging>warpackaging>  
  7.     <version>0.0.1-SNAPSHOTversion>  
  8.     <name>ssm Maven Webappname>  
  9.     <url>http://maven.apache.orgurl>  
  10.     <dependencies>  
  11.   
  12.           
  13.         <dependency>  
  14.             <groupId>junitgroupId>  
  15.             <artifactId>junitartifactId>  
  16.             <version>4.10version>  
  17.             <scope>testscope>  
  18.         dependency>  
  19.   
  20.           
  21.         <dependency>  
  22.             <groupId>org.springframeworkgroupId>  
  23.             <artifactId>spring-contextartifactId>  
  24.             <version>4.1.3.RELEASEversion>  
  25.         dependency>  
  26.         <dependency>  
  27.             <groupId>org.springframeworkgroupId>  
  28.             <artifactId>spring-beansartifactId>  
  29.             <version>4.1.3.RELEASEversion>  
  30.         dependency>  
  31.         <dependency>  
  32.             <groupId>org.springframeworkgroupId>  
  33.             <artifactId>spring-webmvcartifactId>  
  34.             <version>4.1.3.RELEASEversion>  
  35.         dependency>  
  36.         <dependency>  
  37.             <groupId>org.springframeworkgroupId>  
  38.             <artifactId>spring-jdbcartifactId>  
  39.             <version>4.1.3.RELEASEversion>  
  40.         dependency>  
  41.         <dependency>  
  42.             <groupId>org.springframeworkgroupId>  
  43.             <artifactId>spring-aspectsartifactId>  
  44.             <version>4.1.3.RELEASEversion>  
  45.         dependency>  
  46.   
  47.           
  48.         <dependency>  
  49.             <groupId>org.mybatisgroupId>  
  50.             <artifactId>mybatisartifactId>  
  51.             <version>3.4.2version>  
  52.         dependency>  
  53.   
  54.           
  55.         <dependency>  
  56.             <groupId>org.mybatisgroupId>  
  57.             <artifactId>mybatis-springartifactId>  
  58.             <version>1.3.0version>  
  59.         dependency>  
  60.   
  61.           
  62.         <dependency>  
  63.             <groupId>mysqlgroupId>  
  64.             <artifactId>mysql-connector-JavaartifactId>  
  65.             <version>5.1.6version>  
  66.         dependency>  
  67.   
  68.           
  69.         <dependency>  
  70.             <groupId>apache-log4jgroupId>  
  71.             <artifactId>log4jartifactId>  
  72.             <version>1.2.15version>  
  73.         dependency>  
  74.   
  75.           
  76.         <dependency>  
  77.             <groupId>jstlgroupId>  
  78.             <artifactId>jstlartifactId>  
  79.             <version>1.2version>  
  80.         dependency>  
  81.         <dependency>  
  82.             <groupId>javax.servletgroupId>  
  83.             <artifactId>servlet-apiartifactId>  
  84.             <version>2.5version>  
  85.             <scope>providedscope>  
  86.         dependency>  
  87.         <dependency>  
  88.             <groupId>javax.servletgroupId>  
  89.             <artifactId>jsp-apiartifactId>  
  90.             <version>2.0version>  
  91.             <scope>providedscope>  
  92.         dependency>  
  93.     dependencies>  
  94.     <build>  
  95.         <finalName>ssmfinalName>  
  96.         <plugins>  
  97.             <plugin>  
  98.                 <groupId>org.mybatis.generatorgroupId>  
  99.                 <artifactId>mybatis-generator-maven-pluginartifactId>  
  100.                 <version>1.3.2version>  
  101.                 <configuration>  
  102.                     <verbose>trueverbose>  
  103.                     <overwrite>trueoverwrite>  
  104.                 configuration>  
  105.             plugin>  
  106.         plugins>  
  107.     build>  
  108. project>  

3.然后在src/main/java下新建需要的package,如下图所示
使用maven,实现ssm(spring+springmvc+mybatis)三大框架的整合DEMO_第1张图片

各包的用途如下:controller-无需多说,放的是springmvc的controller文件
mode-放的实体类
service-业务层
service.impl-业务实现层
mapper-mybatis的操作数据库的接口文件,类似于dao层(这里需要注意src/main/resources下的目录,和org.bb.ssm.mapper包名一样)
4.此处我使用mybatis-generator自动生成映射类、dao、xml文件,具体做法是:现在pom.xml中引用mybatis-generator这个插件(前面我们已经引进),在src/main/resource下新建generatorConfig.xml,内容如下:
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. >  
  3. <generatorConfiguration>  
  4.       
  5.       
  6.       
  7.       
  8.     <classPathEntry  
  9.         location="D:\Program Files\apache-maven-3.3.9\repository\mysql\mysql-connector-java\5.1.6\mysql-connector-Java-5.1.6.jar" />  
  10.       
  11.     <context id="context1">  
  12.       
  13.         <commentGenerator>  
  14.               
  15.             <property name="suppressAllComments" value="true">property>  
  16.               
  17.             <property name="suppressDate" value="true">property>  
  18.         commentGenerator>  
  19.           
  20.         <jdbcConnection  
  21.             connectionURL="jdbc:mysql://127.0.0.1:3306/ssm?useUnicode=true&characterEncoding=UTF-8"  
  22.             driverClass="com.mysql.jdbc.Driver" password="root" userId="root" />  
  23.               
  24.             
  25.         <javaTypeResolver>    
  26.                 
  27.             <property name="forceBigDecimals" value="false"/>    
  28.         javaTypeResolver>    
  29.           
  30.           
  31.         <javaModelGenerator targetPackage="org.bb.ssm.model"  
  32.             targetProject="D:\SXYC\workspace\ssm\src\main\java" />  
  33.               
  34.           
  35.         <sqlMapGenerator targetPackage="org.bb.ssm.mapper"  
  36.             targetProject="D:\SXYC\workspace\ssm\src\main\resources" />  
  37.           
  38.           
  39.         <javaClientGenerator targetPackage="org.bb.ssm.mapper"  
  40.             targetProject="D:\SXYC\workspace\ssm\src\main\java" type="XMLMAPPER" />  
  41.               
  42.         <table schema="ssm" tableName="userinfo"  domainObjectName="UserInfo" enableCountByExample="false"    
  43.             enableDeleteByExample="false" enableSelectByExample="false"    
  44.             enableUpdateByExample="false">  
  45.               
  46.         table>  
  47.     context>  
  48. generatorConfiguration>  
[html] view plain copy
  1.   
5.鼠标右击pom.xml,run as  "Maven build" 在goals中输入命令:mybatis-generator:generate,即可自动生成相应文件。
6.下面开始配置spring与mybatis的整合配置--applicationContext-mybatis.xml,直接上配置:
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  7.         http://www.springframework.org/schema/beans/spring-beans.xsd    
  8.         http://www.springframework.org/schema/mvc   
  9.         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd    
  10.         http://www.springframework.org/schema/context   
  11.         http://www.springframework.org/schema/context/spring-context.xsd  
  12.         http://www.springframework.org/schema/tx    
  13.         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">  
  14.   
  15.       
  16.       
  17.     <bean id="dataSource"  
  18.         class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  19.         <property name="driverClassName" value="com.mysql.jdbc.Driver">property>  
  20.         <property name="url" value="jdbc:mysql://localhost:3306/ssm">property>  
  21.         <property name="username" value="root">property>  
  22.         <property name="password" value="root">property>  
  23.     bean>  
  24.   
  25.       
  26.     <bean id="txManager"  
  27.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  28.         <property name="dataSource" ref="dataSource">property>  
  29.     bean>  
  30.   
  31.       
  32.     <settings>  
  33.         <setting name="logImpl" value="STDOUT_LOGGING" />  
  34.           
  35.         <setting name="lazyLoadingEnabled" value="true" />  
  36.         <setting name="aggressiveLazyLoading" value="false" />  
  37.         <setting name="mapUnderscoreToCamelCase" value="true" />  
  38.     settings>  
  39.       
  40.     <typeAliases>  
  41.         <typeAlias type="org.bb.ssm.model.UserInfo" alias="UserInfo"/>  
  42.     typeAliases>  
  43.     <mappers>  
  44.         <package name="org.bb.ssm.mapper"/>  
  45.     mappers>  
  46. configuration>  
8.下来是springMVC的配置文件spring-MVC.xml:
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  7.         http://www.springframework.org/schema/beans/spring-beans.xsd    
  8.         http://www.springframework.org/schema/mvc   
  9.         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd    
  10.         http://www.springframework.org/schema/context   
  11.         http://www.springframework.org/schema/context/spring-context.xsd  
  12.         http://www.springframework.org/schema/tx    
  13.         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">  
  14.       
  15.     <mvc:annotation-driven/>  
  16.       
  17.     <context:component-scan base-package="org.bb.ssm.controller"/>  
  18.     <context:component-scan base-package="org.bb.ssm.service.Impl"/>  
  19.       
  20.       
  21.     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  22.         <property name="prefix" value="/WEB-INF/view/">property>  
  23.         <property name="suffix" value=".jsp">property>  
  24.     bean>  
  25.       
  26.     <mvc:default-servlet-handler/>  
  27. beans>  
9.web.xml配置:
[html] view plain copy
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     
  5.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  6.   
  7.       
  8.     <listener>  
  9.         <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>  
  10.     listener>  
  11.   
  12.       
  13.     <context-param>  
  14.         <param-name>contextConfigLocationparam-name>  
  15.         <param-value>classpath:applicationContext-mybatis.xmlparam-value>  
  16.     context-param>  
  17.       
  18.     <servlet>  
  19.         <servlet-name>springMVCservlet-name>  
  20.         <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>  
  21.         <init-param>  
  22.             <param-name>contextConfigLocationparam-name>  
  23.             <param-value>classpath:spring-MVC.xmlparam-value>  
  24.         init-param>  
  25.         <load-on-startup>1load-on-startup>  
  26.     servlet>  
  27.   
  28.     <servlet-mapping>  
  29.         <servlet-name>springMVCservlet-name>  
  30.         <url-pattern>/url-pattern>  
  31.     servlet-mapping>  
  32.   
  33.       
  34.     <listener>  
  35.         <listener-class>org.springframework.web.util.IntrospectorCleanupListenerlistener-class>  
  36.     listener>  
  37.       
  38.       
  39.     <filter>  
  40.         <filter-name>HiddenHttpMethodFilterfilter-name>  
  41.         <filter-class>org.springframework.web.filter.HiddenHttpMethodFilterfilter-class>  
  42.     filter>  
  43.       
  44.     <filter-mapping>  
  45.         <filter-name>HiddenHttpMethodFilterfilter-name>  
  46.         <url-pattern>/*url-pattern>  
  47.     filter-mapping>  
  48.       
  49.     <welcome-file-list>  
  50.         <welcome-file>index.jspwelcome-file>  
  51.     welcome-file-list>  
  52. web-app>  
9.log4j日志配置:
[html] view plain copy
  1. ### set log levels ###     
  2. log4j.rootLogger = info , Console , D    
  3. #Console    
  4. log4j.appender.Console=org.apache.log4j.ConsoleAppender    
  5. log4j.appender.Console.layout=org.apache.log4j.PatternLayout    
  6. log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n    
  7. log4j.logger.java.sql.ResultSet=INFO    
  8. log4j.logger.org.apache=INFO    
  9. log4j.logger.java.sql.Connection=INFO    
  10. log4j.logger.java.sql.Statement=INFO    
  11. log4j.logger.java.sql.PreparedStatement=INFO    
  12. #output2file    
  13. log4j.appender.D = org.apache.log4j.DailyRollingFileAppender     
  14. log4j.appender.D.File = D\:/logs/log.log     
  15. log4j.appender.D.Append = true     
  16. log4j.appender.D.Threshold = INFO \#\# \u00E8\u00BE\u0093\u00E5\u0087\u00BAinfo\u00E7\u00BA\u00A7\u00E5\u0088\u00AB\u00E4\u00BB\u00A5\u00E4\u00B8\u008A\u00E7\u009A\u0084\u00E6\u0097\u00A5\u00E5\u00BF\u0097     
  17. log4j.appender.D.layout = org.apache.log4j.PatternLayout     
  18. log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [ %t\:%r ] - [ %p ] %m%n     
10.补贴上数据库的建表sql:
[html] view plain copy
  1. CREATE DATABASE /*!32312 IF NOT EXISTS*/`ssm` /*!40100 DEFAULT CHARACTER SET utf8 */;  
  2.   
  3. USE `ssm`;  
  4.   
  5. /*Table structure for table `userinfo` */  
  6.   
  7. DROP TABLE IF EXISTS `userinfo`;  
  8.   
  9. CREATE TABLE `userinfo` (  
  10.   `user_id` int(11) NOT NULL AUTO_INCREMENT,  
  11.   `user_name` varchar(30) DEFAULT NULL,  
  12.   `user_age` int(3) DEFAULT NULL,  
  13.   `user_address` varchar(400) DEFAULT NULL,  
  14.   PRIMARY KEY (`user_id`)  
  15. ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;  
11.配置到这里已经完成,启动项目访问欢迎页面,如果看到熟悉的Hello world 代表整合成功了。
使用maven,实现ssm(spring+springmvc+mybatis)三大框架的整合DEMO_第2张图片

12.创建业务层接口文件,UserInfoService.java 和 对应的实现类 UserInfoServiceImpl.java
[html] view plain copy
  1. package org.bb.ssm.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.bb.ssm.model.UserInfo;  
  6.   
  7. /**  
  8.  * Dao层是和数据库打交道的,Service层会封装具体的业务。有点抽象.. e.g. 用户管理系统  
  9.  * dao封装了用户的增删改查。而业务上要求批量删除用户,Service就可以封装出一个批量删除用户的功能  
  10.  * ,但是实现只是循环调用dao的单个删除    
  11.  * 此处没有特殊的业务需求,所以和dao层写的一模一样  
  12.  *   
  13.  * @author Administrator  
  14.  *  
  15.  */  
  16. public interface UserInfoService {  
  17.   
  18.     List<UserInfo> findAll();  
  19.       
  20.     int deleteByPrimaryKey(Integer userId);  
  21.   
  22.     int insert(UserInfo record);  
  23.   
  24.     int insertSelective(UserInfo record);  
  25.   
  26.     UserInfo selectByPrimaryKey(Integer userId);  
  27.   
  28.     int updateByPrimaryKeySelective(UserInfo record);  
  29.   
  30.     int updateByPrimaryKey(UserInfo record);  
  31. }  
[html] view plain copy
  1. package org.bb.ssm.service.Impl;  
  2.   
  3. import java.util.List;  
  4.   
  5. import javax.annotation.Resource;  
  6.   
  7. import org.bb.ssm.mapper.UserInfoMapper;  
  8. import org.bb.ssm.model.UserInfo;  
  9. import org.bb.ssm.service.UserInfoService;  
  10. import org.springframework.stereotype.Service;  
  11. import org.springframework.transaction.annotation.Transactional;  
  12. //可以消除xml中对bean的配置  
  13. @Service  
  14. // 此处使用spring的声明式事务,不在使用sqlsession和提交事务了  
  15. @Transactional  
  16. public class UserInfoServiceImpl implements UserInfoService {  
  17.   
  18.     @Resource  
  19.     /**  
  20.      * @Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,  
  21.      * 而@Resource默认按 byName自动注入罢了。@Resource有两个属性是比较重要的,  
  22.      * 分是name和type,Spring将@Resource注解的name属性解析为bean的名字,  
  23.      * 而type属性则解析为bean的类型。所以如果使用name属性,则使用byName的自动注入策略,  
  24.      * 而使用type属性时则使用byType自动注入策略。如果既不指定name也不指定type属性,  
  25.      * 这时将通过反射机制使用byName自动注入策略。 @Resource装配顺序  
  26.      *                                                                    
  27.      *1.如果同时指定了name和type,则从Spring上下文中找到唯一匹配的bean进行装配,找不到则抛出异常  
  28.      *2.  
  29.      *如果指定了name,则从上下文中查找名称(id)匹配的bean进行装配,找不到则抛出异常  
  30.      *3.  
  31.      *如果指定了type,则从上下文中找到类型匹配的唯一bean进行装配,找不到或者找到多个,都会抛出异常  
  32.      *4.  
  33.      *如果既没有指定name,又没有指定type,则自动按照byName方式进行装配;如果没有匹配,则回退为一个原始类型进行匹配,如果匹配则自动装配;  
  34.      */  
  35.     private UserInfoMapper mapper;  
  36.   
  37.     /**  
  38.      * 查询UserInfo表所有数据  
  39.      */  
  40.     @Override  
  41.     public List<UserInfo> findAll() {  
  42.         List<UserInfo> list = mapper.findAll();  
  43.         return list;  
  44.     }  
  45.       
  46.     @Override  
  47.     public int deleteByPrimaryKey(Integer userId) {  
  48.         return mapper.deleteByPrimaryKey(userId);  
  49.     }  
  50.   
  51.     @Override  
  52.     public int insert(UserInfo record) {  
  53.         return mapper.insert(record);  
  54.     }  
  55.   
  56.     @Override  
  57.     public int insertSelective(UserInfo record) {  
  58.         return mapper.insertSelective(record);  
  59.     }  
  60.   
  61.     @Override  
  62.     public UserInfo selectByPrimaryKey(Integer userId) {  
  63.         return mapper.selectByPrimaryKey(userId);  
  64.     }  
  65.   
  66.     @Override  
  67.     public int updateByPrimaryKeySelective(UserInfo record) {  
  68.         return mapper.updateByPrimaryKeySelective(record);  
  69.     }  
  70.   
  71.     @Override  
  72.     public int updateByPrimaryKey(UserInfo record) {  
  73.         return mapper.updateByPrimaryKey(record);  
  74.     }  
  75.   
  76. }  
13.创建controller文件,UserInfoCotroller.java
[html] view plain copy
  1. package org.bb.ssm.controller;  
  2.   
  3. import java.util.List;  
  4. import java.util.Map;  
  5.   
  6. import org.bb.ssm.model.UserInfo;  
  7. import org.bb.ssm.service.UserInfoService;  
  8. import org.springframework.beans.factory.annotation.Autowired;  
  9. import org.springframework.stereotype.Controller;  
  10. import org.springframework.web.bind.annotation.ModelAttribute;  
  11. import org.springframework.web.bind.annotation.PathVariable;  
  12. import org.springframework.web.bind.annotation.RequestMapping;  
  13. import org.springframework.web.bind.annotation.RequestMethod;  
  14. import org.springframework.web.bind.annotation.RequestParam;  
  15.   
  16. @Controller  
  17. @RequestMapping(value="/user")  
  18. public class UserInfoCotroller {  
  19.       
  20.     @Autowired  
  21.     private UserInfoService userInfoService;  
  22.       
  23.     /**  
  24.      * 得到所有用户信息  
  25.      * @param map  
  26.      * @return  
  27.      */  
  28.     @RequestMapping(value="/getAllUser")  
  29.     public String getAllUser(Map<String, Object> map){  
  30.         List<UserInfo> userList = userInfoService.findAll();  
  31.         map.put("ALLUSER", userList);  
  32.         return "allUser";  
  33.     }  
  34.     /**  
  35.      * 通过handler前往添加用户页面  
  36.      * @param map  
  37.      * @return  
  38.      */  
  39.     @RequestMapping(value="/addUser",methodRequestMethod.GET)  
  40.     public String addUser(Map<String, Object> map){  
  41.         //因为页面使用spring的form标签,其中属性modelAttribute需要存在bean 要不会报错  
  42.         map.put("command", new UserInfo());  
  43.         return "addUser";  
  44.     }  
  45.       
  46.     /**  
  47.      * 添加用户操作  
  48.      * @param userinfo  
  49.      * @return  
  50.      */  
  51.     @RequestMapping(value="/addUser",method=RequestMethod.POST)  
  52.     public String save(UserInfo userinfo){  
  53.         int result = userInfoService.insert(userinfo);  
  54.         System.out.println("添加用户的操作结果为:"+result);  
  55.         return "redirect:/user/getAllUser";  
  56.     }  
  57.     /**  
  58.      * 删除用户操作  
  59.      * @param id  
  60.      * @return  
  61.      */  
  62.     @RequestMapping(value="/delete/{id}",method=RequestMethod.DELETE)  
  63.     public String delete(@PathVariable(value="id") int id){  
  64.         int result = userInfoService.deleteByPrimaryKey(id);  
  65.         System.out.println("删除用户的操作结果为:"+result+"传递进来的id为:"+id);  
  66.         return "redirect:/user/getAllUser";  
  67.     }  
  68.     /**  
  69.      * 更新前先根据id找到用户信息,回显到页面上  
  70.      * @param id  
  71.      * @param map  
  72.      * @return  
  73.      */  
  74.     @RequestMapping(value="/detail/{id}",method=RequestMethod.GET)  
  75.     public String input(@PathVariable(value="id") Integer id,Map<String, Object> map){  
  76.         map.put("command", userInfoService.selectByPrimaryKey(id));  
  77.         return "addUser";  
  78.     }  
  79.       
  80.     @ModelAttribute  
  81.     public void getUserInfo(@RequestParam(value="userId",required=false) Integer id  
  82.             ,Map<String, Object> map){  
  83.         System.out.println("每个controller 方法都会先调用我哦");  
  84.         if(id != null){  
  85.             System.out.println("update 操作");  
  86.             map.put("userInfo", userInfoService.selectByPrimaryKey(id));  
  87.         }  
  88.         System.out.println("insert  操作");  
  89.     }  
  90.       
  91.     @RequestMapping(value="/addUser",method=RequestMethod.PUT)  
  92.     public String update(UserInfo userinfo){  
  93.         userInfoService.updateByPrimaryKey(userinfo);  
  94.         return "redirect:/user/getAllUser";  
  95.     }  
  96. }  
14.展示页面:分别是allUser.jsp、addUser.jsp
[html] view plain copy
  1. <%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="utf-8"%>  
  3. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  4. >  
  5. <html>  
  6. <head>  
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  8. <title>全部员工title>  

你可能感兴趣的:(ssm)