SSM整合
1.创建sql
创建sql相对应的表及其数据。
2.导入pom相关坐标
详细坐标见day17的pom.xml,有些版本要对应自己的。
3.编写实体类
与sql里的相对应。
4.编写Mapper接口
5. 编写Service接口以及实现
6. 编写Controller
7.编写页面
添加页面:创建在web下的。
列表页面:不是直接访问的,建在WEB-INF下的。
8. 编写相应的配置文件
-
数据库连接信息文件:jdbc.properties
-
日志文件:log4j.properties
-
Web.xml文件:web.xml
<!--spring监听器--> <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的前端控制器--> <servlet> <servlet-name>DispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>DispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!--乱码过滤器--> <filter> <filter-name>CharacterEncodingFilter</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> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
-
Spring配置文件:applicationContext.xml
-
SpringMVC配置文件:spring-mvc.xml
-
MyBatis映射文件:AccountMapper.xml
-
MyBatis核心文件:sqlMapConfig.xml
9.编写业务代码
详见SSM的P198(根据需求
10.Spring整合MyBatis
将Session工厂交给Spring容器管理,从容器中获得执行操作的Mapper实例。
配置声明式事务管理
对应的Service类代码修改