概述
涉及技术
- SpringMVC、Spring、SpringData/JPA 整合完成CRUD、翻页
- 基于Restful风格
- 使用JPA二级缓存
- 使用@PesponseBody注解完成Ajax
搭建环境
1. 配置Spring
2. 配置SpringMVC
3. 加入JPA
4. 加入SpringDataweb.xml
spring配置
<!-- 1. 配置spring : 配置启动IOC 容器的 Listener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
springMVC的配置
<!--2 .配置springMVC 相关 -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- 定位springMvc 配置文件的位置, 另一种方法:servletname-servlet.xml 默认位置 默认在WEB-INFO下
<init-param> <param-name>contextConfigLocation</param-name> <param-value>location</param-value>
</init-param> -->
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
字符编码过滤器
<!--3. 配置字符编码过滤器 必须配置在所有过滤器的最前面() 获取请求参数 或 读取之前被调用否则无效 HiddenHttpMethodFilter
在执行前会调用getFilter 将导致此过滤器无效 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</