三层架构

从代码结构的功能上分为三层

  1. Dao层(data access object) 数据访问层
  2. Servcie 层(或者成为business) 业务层 整合dao层
  3. Controller 控制层 控制页面显示和跳转的

三层之间的调用关系:service调用dao层,controller层调用service层

Mvc

从代码的运行角度上栏分为mvc三层结构

  1. M model 数据模型层
  2. V view 视图层 数据显示层
  3. C controller 控制层

Model层相当于三层架构中的dao+service层 View 相当于jsp或者html 用于显示数据的 Controller 控制层,控制页面的跳转,可以发送和接收view的数据,相当于servlet

Springmvc

执行流程

实习笔记[SpringMVC和SSM整合] - 图1

1. Springmvc使用过程

Idea创建web项目

实习笔记[SpringMVC和SSM整合] - 图2

实习笔记[SpringMVC和SSM整合] - 图3

实习笔记[SpringMVC和SSM整合] - 图4

web.xml版本太低,至少要用web3.0以上

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  6. version="4.0">
  7. </web-app >

修改项目结构,新建java和resources文件夹

实习笔记[SpringMVC和SSM整合] - 图5

实习笔记[SpringMVC和SSM整合] - 图6

运行web项目

实习笔记[SpringMVC和SSM整合] - 图7

实习笔记[SpringMVC和SSM整合] - 图8

实习笔记[SpringMVC和SSM整合] - 图9

实习笔记[SpringMVC和SSM整合] - 图10

实习笔记[SpringMVC和SSM整合] - 图11

实习笔记[SpringMVC和SSM整合] - 图12

实习笔记[SpringMVC和SSM整合] - 图13

实习笔记[SpringMVC和SSM整合] - 图14

Jsp(java server page) java的服务器页面 ,和html区别在于可以在jsp书写java代码,在运行的时候,服务器tomcat会把jsp编译成.class文件,里面的标签,css和js书写方式一模一样

实习笔记[SpringMVC和SSM整合] - 图15

实习笔记[SpringMVC和SSM整合] - 图16

可以自己创建一个jsp或者html文件,直接在浏览器中输入页面 名称访问新的页面

实习笔记[SpringMVC和SSM整合] - 图17

Springmvc入门案例

实习笔记[SpringMVC和SSM整合] - 图18

1. 导入springwebmvc的依赖

  1. <dependencies>
  2. <!--spring-webmvc-->
  3. <dependency>
  4. <groupId>org.springframework</groupId>
  5. <artifactId>spring-webmvc</artifactId>
  6. <version>5.2.4.RELEASE</version>
  7. </dependency>
  8. </dependencies>

2. 配置springmvc.xml

实习笔记[SpringMVC和SSM整合] - 图19

  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"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
  7. <!--扫描controller-->
  8. <context:component-scan base-package="com.ujiuye.controller"/>
  9. <!--配置视图解析器 ,会在controller中方法的返回值上加上前后缀-->
  10. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  11. <property name="prefix" value="/"/> <!--前缀-->
  12. <property name="suffix" value=".jsp"/> <!--后缀-->
  13. </bean>
  14. </beans>

3. 配置web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  6. version="4.0">
  7. <!--中央控制器-->
  8. <servlet>
  9. <servlet-name>mvc</servlet-name>
  10. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  11. <init-param>
  12. <param-name>contextConfigLocation</param-name>
  13. <param-value>classpath:springmvc.xml</param-value>
  14. </init-param>
  15. </servlet>
  16. <servlet-mapping>
  17. <servlet-name>mvc</servlet-name>
  18. <url-pattern>/</url-pattern>
  19. </servlet-mapping>
  20. </web-app>

4. 随便webapp下面创建一个jsp文件

实习笔记[SpringMVC和SSM整合] - 图20

5. 书写HelloController

  1. @Controller
  2. public class HelloController {
  3. @RequestMapping("/h1")
  4. public String hello(){
  5. return "ok";
  6. }
  7. }

浏览器直接访问http://localhost:8080/day07/h1

实习笔记[SpringMVC和SSM整合] - 图21

2. 相关配置

1. 静态资源不拦截

在springmvc.xml中配置 mvc:default-servlet-handler/

2. 数据传递到前台jsp

1.导入jstl的依赖

  1. <!-- jstl jsp标签库包 -->
  2. <dependency>
  3. <groupId>jstl</groupId>
  4. <artifactId>jstl</artifactId>
  5. <version>1.2</version>
  6. </dependency>

2. 在springmvc.xml加入mvc的注解驱动

mvc:annotation-driven/

3. 创建UserBean

  1. public class UserBean {
  2. private int uid;
  3. private String uname;
  4. private String address;
  5. //alt+insert 生成get/set/构造
  6. public UserBean() {
  7. }
  8. public UserBean(int uid, String uname, String address) {
  9. this.uid = uid;
  10. this.uname = uname;
  11. this.address = address;
  12. }
  13. }

4. HelloController

  1. @RequestMapping("/h2")
  2. public String h2(Model model){
  3. UserBean u=new UserBean(1,"张三","西安");
  4. model.addAttribute("user",u);
  5. return "okk";
  6. }
  7. @RequestMapping("/h3")
  8. public String h3(Map map){
  9. UserBean u1=new UserBean(1,"张三","西安");
  10. UserBean u2=new UserBean(2,"李四","宝鸡");
  11. UserBean u3=new UserBean(3,"王五","北京");
  12. List<UserBean> list=new ArrayList<>();
  13. list.add(u1);
  14. list.add(u2);
  15. list.add(u3);
  16. map.put("datas",list);
  17. return "list";
  18. }

5. 创建okk.jsp list.jsp

okk.jsp

  1. <body>
  2. id:${user.uid}
  3. 用户名:${user.uname}
  4. 地址:${user.address}
  5. </body>

list.jsp

  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  3. <html>
  4. <head>
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <table border="1" width="300">
  9. <tr>
  10. <th>编号</th>
  11. <th>姓名</th>
  12. <th>地址</th>
  13. </tr>
  14. <c:forEach items="${datas}" var="u">
  15. <tr>
  16. <td>${u.uid}</td>
  17. <td>${u.uname}</td>
  18. <td>${u.address}</td>
  19. </tr>
  20. </c:forEach>
  21. </table>
  22. </body>
  23. </html>

访问:

http://localhost:8080/day07/h2

实习笔记[SpringMVC和SSM整合] - 图22

http://localhost:8080/day07/h3

实习笔记[SpringMVC和SSM整合] - 图23

执行过程:

先经过controller的方法,在方法中存入了数据,再根据方法的返回值,跳转到指定jsp页面,在jsp页面中获取controller传过来的数据,所有我们在访问的时候,一定是访问controller的方法

3. Ajax做法

1. pom 导入fastjson支持

  1. <!--json-->
  2. <dependency>
  3. <groupId>com.fasterxml.jackson.core</groupId>
  4. <artifactId>jackson-databind</artifactId>
  5. <version>2.9.4</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.fasterxml.jackson.core</groupId>
  9. <artifactId>jackson-annotations</artifactId>
  10. <version>2.9.4</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.fasterxml.jackson.core</groupId>
  14. <artifactId>jackson-core</artifactId>
  15. <version>2.9.4</version>
  16. </dependency>

2. JsonController

  1. @RestController //相当于在当前类所有的方法上面全部加上 @ResponseBody
  2. //RestController 跳转+编码+ //相当于在当前类所有的方法上面全部加上 @ResponseBody
  3. //Controller 跳转页面
  4. @RequestMapping("/json/")
  5. public class JsonController {
  6. @RequestMapping("/h1")
  7. // @ResponseBody //将返回值转成json格式的字符串
  8. public UserBean c1(){
  9. UserBean u=new UserBean(1,"张三","西安");
  10. return u;
  11. }
  12. @RequestMapping("/h3")
  13. public List<UserBean> h3(){
  14. UserBean u1=new UserBean(1,"张三","西安");
  15. UserBean u2=new UserBean(2,"李四","宝鸡");
  16. UserBean u3=new UserBean(3,"王五","北京");
  17. List<UserBean> list=new ArrayList<>();
  18. list.add(u1);
  19. list.add(u2);
  20. list.add(u3);
  21. return list;
  22. }
  23. }

3. Json.jsp

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>ajax请求</title>
  5. <script src="js/jquery.min.js"></script>
  6. <script>
  7. //等待网页加载完成之后执行
  8. $(function () {
  9. //第一种写法
  10. /* $.ajax({
  11. url:"json/h1", //请求路径
  12. dataType:"json", //后台返回的数据格式,默认就是json
  13. success:function (data) {
  14. console.log(data)
  15. var str="id="+data.uid+"姓名:"+data.uname+"地址:"+data.address;
  16. $("#content").html(str);
  17. }
  18. });*/
  19. //ajax的简写方法 解析对象
  20. $.get("json/h1",function (data) {
  21. console.log(data)
  22. var str="id="+data.uid+"姓名:"+data.uname+"地址:"+data.address;
  23. $("#content").html(str);
  24. });
  25. //解析集合
  26. $.get("json/h3",function (data) {
  27. console.log(data);
  28. var str="";
  29. /* for(var i=0;i<data.length;i++){
  30. var user=data[i];
  31. str+="<tr><td>"+user.uid+"</td><td>"+user.uname+"</td><td>"+user.address+"</td></tr>"
  32. }*/
  33. $(data).each(function (i,user) {
  34. str+="<tr><td>"+user.uid+"</td><td>"+user.uname+"</td><td>"+user.address+"</td></tr>"
  35. })
  36. $("#head").after(str);
  37. })
  38. })
  39. </script>
  40. </head>
  41. <body>
  42. <div id="content">
  43. </div>
  44. <table border="1" width="300">
  45. <tr id="head">
  46. <th>编号</th>
  47. <th>姓名</th>
  48. <th>地址</th>
  49. </tr>
  50. </table>
  51. </body>
  52. </html>

直接访问json.jsp 文件

http://localhost:8080/day07/json.jsp

实习笔记[SpringMVC和SSM整合] - 图24

执行过程,直接访问页面jsp或者html,在页面中使用ajax请求controller中数据,拿到json数据直接自己解析

4. 后台接收前端传递过来参数

Get请求:直接在浏览器的地址栏中发送数据,以?参数=值&参数2=值2

实习笔记[SpringMVC和SSM整合] - 图25

Post提交,以请求体的方式提交的,在地址栏中表面上看不到

实习笔记[SpringMVC和SSM整合] - 图26

Post提交是没有数据量限制的,但是get请求一般限制大小是4K,所以提交文件的时候必须是post提交,但是get提交速度快

1. 如果碰到后台接受乱码,在web.xml中配置编码过滤器
  1. <!--编码过滤器-->
  2. <filter>
  3. <filter-name>encode</filter-name>
  4. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  5. <init-param>
  6. <param-name>encoding</param-name>
  7. <param-value>utf-8</param-value>
  8. </init-param>
  9. </filter>
  10. <filter-mapping>
  11. <filter-name>encode</filter-name>
  12. <url-pattern>/*</url-pattern>
  13. </filter-mapping>
  14. </web-app>

2. 创建ParamController
  1. @Controller
  2. @RequestMapping("/form/")
  3. public class ParamController {
  4. /**
  5. * @param username 变量名一定和前端传过来拿的参数名保持一致
  6. * @param password 变量名一定和前端传过来拿的参数名保持一致
  7. * @return
  8. */
  9. @RequestMapping("p1")
  10. public String p1(String username,String password){
  11. System.out.println("name=="+username+"psw=="+password);
  12. return "ok";
  13. }
  14. }

3. 创建一个表单 regist.html
  1. <form action="form/p1" method="post">
  2. <div>
  3. 用户名:<input name="username">
  4. </div>
  5. <div>
  6. 密码:<input name="password">
  7. </div>
  8. <div>
  9. <input type="submit" value="注册">
  10. </div>
  11. </form>

错误类型: 4:前端错误 404:路径错误 400:前后端参数类型不匹配 5:服务器内部错误,java方法错误 接收参数设置默认值 @RequestMapping(“p1”) public String p1(String username, @RequestParam(defaultValue = “123”) String password, @RequestParam(defaultValue = “100”) Integer id){ System.out.println(“name==”+username+”psw==”+password +”id=”+id); return “ok”; } http://localhost:8080/day07/form/p1?username=张三 对象接收参数 @RequestMapping(“p2”) public String p2(UserBean u){ System.out.println(u); return “ok”; } 访问: http://localhost:8080/day07/form/p2?uid=200&uname=admin&address=西安 前台传过来的参数名和对象中属性名保持一致

3. SSM整合

实习笔记[SpringMVC和SSM整合] - 图27

1. Pom

  1. <properties>
  2. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3. <maven.compiler.source>1.8</maven.compiler.source>
  4. <maven.compiler.target>1.8</maven.compiler.target>
  5. <spring.version>5.2.8.RELEASE</spring.version>
  6. </properties>
  7. <dependencies>
  8. <!--springmvc的依赖-->
  9. <dependency>
  10. <groupId>org.springframework</groupId>
  11. <artifactId>spring-webmvc</artifactId>
  12. <version>${spring.version}</version>
  13. </dependency>
  14. <!-- Spring 整合Jdbc -->
  15. <dependency>
  16. <groupId>org.springframework</groupId>
  17. <artifactId>spring-jdbc</artifactId>
  18. <version>${spring.version}</version>
  19. </dependency>
  20. <!-- Spring面向切面编程 -->
  21. <dependency>
  22. <groupId>org.springframework</groupId>
  23. <artifactId>spring-aspects</artifactId>
  24. <version>${spring.version}</version>
  25. </dependency>
  26. <!--servlet-->
  27. <dependency>
  28. <groupId>javax.servlet</groupId>
  29. <artifactId>javax.servlet-api</artifactId>
  30. <version>3.0.1</version>
  31. <scope>provided</scope>
  32. </dependency>
  33. <!-- jstl jsp标签库包 -->
  34. <dependency>
  35. <groupId>jstl</groupId>
  36. <artifactId>jstl</artifactId>
  37. <version>1.2</version>
  38. <scope>provided</scope>
  39. </dependency>
  40. <!--MyBatis -->
  41. <dependency>
  42. <groupId>org.mybatis</groupId>
  43. <artifactId>mybatis</artifactId>
  44. <version>3.4.2</version>
  45. </dependency>
  46. <!-- MyBatis整合Spring的适配包 -->
  47. <dependency>
  48. <groupId>org.mybatis</groupId>
  49. <artifactId>mybatis-spring</artifactId>
  50. <version>2.0.3</version>
  51. </dependency>
  52. <!--引入pageHelper分页插件 PageInfo -->
  53. <dependency>
  54. <groupId>com.github.pagehelper</groupId>
  55. <artifactId>pagehelper</artifactId>
  56. <version>5.1.2</version>
  57. </dependency>
  58. <!--MySQL-->
  59. <dependency>
  60. <groupId>mysql</groupId>
  61. <artifactId>mysql-connector-java</artifactId>
  62. <version>5.1.47</version>
  63. </dependency>
  64. <!-- 阿里巴巴 数据源 druid -->
  65. <dependency>
  66. <groupId>com.alibaba</groupId>
  67. <artifactId>druid</artifactId>
  68. <version>1.1.10</version>
  69. </dependency>
  70. <!--json-->
  71. <dependency>
  72. <groupId>com.fasterxml.jackson.core</groupId>
  73. <artifactId>jackson-databind</artifactId>
  74. <version>2.9.4</version>
  75. </dependency>
  76. <dependency>
  77. <groupId>com.fasterxml.jackson.core</groupId>
  78. <artifactId>jackson-annotations</artifactId>
  79. <version>2.9.4</version>
  80. </dependency>
  81. <dependency>
  82. <groupId>com.fasterxml.jackson.core</groupId>
  83. <artifactId>jackson-core</artifactId>
  84. <version>2.9.4</version>
  85. </dependency>
  86. <!--文件上传-->
  87. <dependency>
  88. <groupId>commons-fileupload</groupId>
  89. <artifactId>commons-fileupload</artifactId>
  90. <version>1.4</version>
  91. </dependency>
  92. <!--读取excel文件-->
  93. <dependency>
  94. <groupId>org.apache.poi</groupId>
  95. <artifactId>poi</artifactId>
  96. <version>3.17</version>
  97. </dependency>
  98. <dependency>
  99. <groupId>org.apache.poi</groupId>
  100. <artifactId>poi-ooxml</artifactId>
  101. <version>3.17</version>
  102. </dependency>
  103. </dependencies>

2. PersonBean

  1. public class PersonBean {
  2. private Integer pid;
  3. private String pname;
  4. //alt+insert 生成get/set
  5. }

3. personDao

  1. public interface PersonDao {
  2. int add(PersonBean p);
  3. int del(Integer id);
  4. int update(PersonBean p);
  5. List<PersonBean> findAll();
  6. }

4. PersonService

  1. @Service
  2. public class PersonService {
  3. @Autowired
  4. private PersonDao dao;
  5. public boolean add(PersonBean p){
  6. return dao.add(p)>0?true:false;
  7. }
  8. public boolean del(Integer id){
  9. return dao.del(id)>0?true:false;
  10. }
  11. public boolean update(PersonBean p){
  12. return dao.update(p)>0?true:false;
  13. }
  14. public List<PersonBean> findAll(){
  15. return dao.findAll();
  16. }
  17. }

5. PersonController

  1. @RestController
  2. @RequestMapping("/person/")
  3. public class PersonController {
  4. @Autowired
  5. private PersonService service;
  6. @RequestMapping("add")
  7. public boolean addPerson(PersonBean p){
  8. return service.add(p);
  9. }
  10. @RequestMapping("del")
  11. public boolean delPerson(Integer pid){
  12. return service.del(pid);
  13. }
  14. @RequestMapping("update")
  15. public boolean updatePerson(PersonBean p){
  16. return service.update(p);
  17. }
  18. @RequestMapping("showAll")
  19. public List<PersonBean> showAllPerson(){
  20. return service.findAll();
  21. }
  22. }

6 mybatis_conf.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6. </configuration>

7. PersonMapper.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ujiuye.dao.PersonDao">
  6. <insert id="add" parameterType="com.ujiuye.bean.PersonBean">
  7. insert person(pname)values(#{pname})
  8. </insert>
  9. <delete id="del">
  10. delete from person where pid=#{0}
  11. </delete>
  12. <update id="update" parameterType="com.ujiuye.bean.PersonBean">
  13. update person set pname=#{pname} where pid=#{pid}
  14. </update>
  15. <select id="findAll" resultType="com.ujiuye.bean.PersonBean">
  16. select * from person
  17. </select>
  18. </mapper>

8. db.properties

  1. url=jdbc:mysql://localhost:3306/tt?characterEncoding=utf-8
  2. driver=com.mysql.jdbc.Driver
  3. user=root
  4. password=123456

9. spring_core.xml

  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"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  8. http://www.springframework.org/schema/context
  9. https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
  10. <!--扫描包注解-->
  11. <context:component-scan base-package="com.ujiuye.service"/>
  12. <!--读取properties配置文件-->
  13. <context:property-placeholder location="classpath:db.properties"/>
  14. <!--配置数据源-->
  15. <bean class="com.alibaba.druid.pool.DruidDataSource" id="ds">
  16. <property name="driverClassName" value="${driver}"/>
  17. <property name="url" value="${url}"/>
  18. <property name="username" value="${user}"/>
  19. <property name="password" value="${password}"/>
  20. </bean>
  21. <bean class="org.mybatis.spring.SqlSessionFactoryBean">
  22. <property name="dataSource" ref="ds"/>
  23. <property name="configLocation" value="classpath:mybatis/mybatis_conf.xml"/>
  24. <property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"/>
  25. </bean>
  26. <!--扫描dao层包-->
  27. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  28. <property name="basePackage" value="com.ujiuye.dao"/>
  29. </bean>
  30. </beans>

10. web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  6. version="4.0">
  7. <context-param>
  8. <param-name>contextConfigLocation</param-name>
  9. <param-value>classpath:spring/spring_core.xml</param-value>
  10. </context-param>
  11. <!--监听器,监听到服务器一旦启动,自动读取context-param的参数-->
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15. <!--中央控制器-->
  16. <servlet>
  17. <servlet-name>mvc</servlet-name>
  18. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  19. <init-param>
  20. <param-name>contextConfigLocation</param-name>
  21. <param-value>classpath:spring/springmvc.xml</param-value>
  22. </init-param>
  23. </servlet>
  24. <servlet-mapping>
  25. <servlet-name>mvc</servlet-name>
  26. <url-pattern>/</url-pattern>
  27. </servlet-mapping>
  28. <!--编码过滤器-->
  29. <filter>
  30. <filter-name>encode</filter-name>
  31. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  32. <init-param>
  33. <param-name>encoding</param-name>
  34. <param-value>utf-8</param-value>
  35. </init-param>
  36. </filter>
  37. <filter-mapping>
  38. <filter-name>encode</filter-name>
  39. <url-pattern>/*</url-pattern>
  40. </filter-mapping>
  41. </web-app>

11. 测试:

添加:

http://localhost:8080/day07/person/add?pname=admin

实习笔记[SpringMVC和SSM整合] - 图28

删除

http://localhost:8080/day07/person/del?pid=14

实习笔记[SpringMVC和SSM整合] - 图29

修改:

http://localhost:8080/day07/person/update?pid=15&pname=王五

实习笔记[SpringMVC和SSM整合] - 图30

查询

http://localhost:8080/day07/person/showAll

实习笔记[SpringMVC和SSM整合] - 图31