(重要) 快速的搭建ssm框架(聚合工程) 主要就是5个配置文件

(重要) 快速的搭建ssm框架(聚合工程)   主要就是5个配置文件
搭建的详细步骤见: https://blog.csdn.net/AdamCafe/article/details/91491025SSM聚合工程 项目结构如下:ssm_dao接口 实体类 接口映射文件 applicationContextion-dao.xml 配置文件 测试类代码如下:?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:phttp://www.springframework.org/schema/p xmlns:contexthttp://www.springframework.org/schema/context xmlns:txhttp://www.springframework.org/schema/tx xmlns:mvchttp://www.springframework.org/schema/mvc xmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBean property namedataSource refdataSource/property /bean bean iddataSource classcom.alibaba.druid.pool.DruidDataSource property namedriverClassName valuecom.mysql.jdbc.Driver/property property nameurl valuejdbc:mysql:///springdb1/property property nameusername valueroot/property property namepassword valueroot/property /bean bean idmapperScannerConfigurer classorg.mybatis.spring.mapper.MapperScannerConfigurer property namebasePackage valuebank.dao/property /bean /beans代码如下:package User; import bank.dao.UserDao; import bank.domain.User; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Test; import java.io.IOException; import java.io.InputStream; import java.util.List; public class testUserDao { Test public void testUserDao() throws IOException { InputStream is Resources.getResourceAsStream(sqlMapConfig.xml); SqlSessionFactoryBuilder builder new SqlSessionFactoryBuilder(); SqlSessionFactory factory builder.build(is); SqlSession session factory.openSession(); UserDao userDao session.getMapper(UserDao.class); ListUser list userDao.findAll(); for (User user : list) { System.out.println(user); } session.commit(); session.close(); } }ssm_service接口 接口实现类 applicationContext-service.xml配置文件 测试类?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:phttp://www.springframework.org/schema/p xmlns:contexthttp://www.springframework.org/schema/context xmlns:txhttp://www.springframework.org/schema/tx xmlns:mvchttp://www.springframework.org/schema/mvc xmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd !--包扫描-- context:component-scan base-packagebank.service/context:component-scan !-- 引入dao的配置文件 -- import resourceapplicationContext-dao.xml/import !--事物配置: xml配置-- !--1 创建事务管理器-- bean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManager property namedataSource refdataSource/property /bean !--2 事务通知-- tx:advice idtxAdvice tx:attributes tx:method namesave*/ tx:method nameupdate*/ tx:method namedelete*/ tx:method namefind* propagationSUPPORTS read-onlytrue/ tx:method name*/ /tx:attributes /tx:advice !--3 配置事物AOP-- aop:config aop:pointcut idpt expressionexecution(* bank.service.*.impl.*.*(..))/aop:pointcut aop:advisor advice-reftxAdvice pointcut-refpt/aop:advisor /aop:config /beans测试package test; import bank.domain.User; import bank.service.UserService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.List; RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations classpath:applicationContext-service.xml) public class testUserService { Autowired private UserService userService; Test public void test(){ ListUser users userService.findAll(); for (User user : users) { System.out.println(user); } } }ssm_webcontroller springmvc.xml配置文件 web.xml配置文件?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:phttp://www.springframework.org/schema/p xmlns:contexthttp://www.springframework.org/schema/context xmlns:txhttp://www.springframework.org/schema/tx xmlns:mvchttp://www.springframework.org/schema/mvc xmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd !--包扫描-- context:component-scan base-packagebank.controller/context:component-scan !--1 视图解析器-- bean idviewResolver classorg.springframework.web.servlet.view.InternalResourceViewResolver property nameprefix value/WEB-INF/pages//property property namesuffix value.jsp/property /bean !--日期转换器-- !--bean idconversionService classorg.springframework.context.support.ConversionServiceFactoryBean property nameconverters list bean classweb.converter.StringToDateConverter/bean /list /property /bean-- !--注解驱动-- !--将日期转换器注册到mvc中-- mvc:annotation-driven /mvc:annotation-driven /beans?xml version1.0 encodingUTF-8? web-app xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlnshttp://java.sun.com/xml/ns/javaee xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd version2.5 !--监听器-- listener listener-classorg.springframework.web.context.ContextLoaderListener/listener-class /listener context-param param-namecontextConfigLocation/param-name param-valueclasspath:applicationContext-service.xml/param-value /context-param !--解决post乱码-- filter filter-namecharacterEncodingFilter/filter-name filter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-class init-param param-nameencoding/param-name param-valueutf-8/param-value /init-param init-param param-nameforceEncoding/param-name param-valuetrue/param-value /init-param /filter filter-mapping filter-namecharacterEncodingFilter/filter-name url-pattern/*/url-pattern /filter-mapping servlet servlet-namespringmvc/servlet-name servlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class !--指定加载的配置文件,通过参数contextConfigLocation加载-- init-param param-namecontextConfigLocation/param-name param-valueclasspath:springmvc.xml/param-value /init-param !--指定加载顺序-- load-on-startup1/load-on-startup /servlet servlet-mapping servlet-namespringmvc/servlet-name url-pattern//url-pattern /servlet-mapping /web-app最后 部署tomcat进行测试