SSM个人思路总结
1、整体技术点
后端框架SSM:SpringMVC+Spring+MyBatis
前端框架:BootStrap
分页-PageHelper
2、环境搭建
2.1创建maven工程
通过idea工具,使用骨架的webapp方式创建或者跳过骨架进行创建;其中可能会缺少web.xml文件;下面是xml中一部分:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
</web-app>
2.2、引入依赖的jar包
可以自行去maven官网上去下载以下相关的jar包
Spring相关
SpringMVC相关
MyBatis相关
数据库连接池
数据库驱动
JSTL
servlet-api
Junit 单元测试
Log4j 日志记录
Hibernate Validate 数据校验
Jackson @ResponseBody返回JSON数据
文件上传等
2.3、引用前端内容
css 文件、fonts 文件、js 文件、jQuery 文件
(可以去BootStrap官网上去找,自己练习就随便写个页面)
2.4、添加web文件
思路:项目最先加载的配置文件,所以里面先要加载Spring容器、再添加字符编码过滤器、Rest风格的URI、配置前端控制器
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<!-- 加载Spring容器 -->
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 字符编码过滤器,放在所有过滤器最前面 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
<!-- <init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param> -->
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 使用Rest风格的URI,将页面普通的POST请求转为指定的delete和put请求 -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>