一.ssm框架搭建
1.项目准备(创建项目-添加依赖-添加配置文件)
2.建包controller、service、mapper、entity、filter(过滤器)、util(工具包)
3.编写中文乱码过滤器类(CharsetEncoding),实现Filter接口
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
4.配置web.xml文件
1.配置过滤器
<filter>
<filter-name>encoding</filter-name>
<!--自己写的过滤器类-->
<filter-class>cx.sunyanshu.filter.CharsetEncoding</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
2.加载spring配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
3.配置监听器:监听spring文件是否被加载
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
4.配置前端控制器并加载springmvc配置文件
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--加载springmvc配置文件-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
5.配置jdbc.properties文件
jdbcs.driver=com.mysql.jdbc.Driver
jdbcs.url=jdbc:mysql:/
jdbcs.uname