超详细整合SSM框架--(Spring + Spring MVC + MyBatis)

立山  金牌会员 | 2023-7-16 18:59:16 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 931|帖子 931|积分 2793

超详细整合SSM框架--(Spring + Spring MVC + MyBatis)

阅读该文章之前首先要清楚Spring框架,SpringMVC框架,Mybatis框架。
SSM框架,是Spring + Spring MVC + MyBatis的缩写,这个是继SSH之后,目前比较主流的Java EE企业级框架,适用于搭建各种大型的企业级应用系统。
SpringMVC框架:

MVC简介
MVC 全名是 Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写, 是一种用于设计创建 Web 应用程序表现层的模式。
Model(模型): 通常指的就是我们的数据模型。作用一般情况下用于封装数据。
View(视图): 通常指的就是我们的 jsp 或者 html。作用一般就是展示数据的。 通常视图是依据模型数据创建的。
Controller(控制器): 是应用程序中处理用户交互的部分。作用一般就是处理程序逻辑的。
SpringMVC 是一种基于 Java 的实现 MVC 设计模型的请求驱动类型的轻量级 Web 框架,属于 Spring FrameWork 的后续产品,已经融合在 Spring Web Flow 里面。Spring 框架提供了构建 Web
应用程序的全功能 MVC 模块。使用 Spring 可插入的 MVC 架构,从而在使用 Spring 进行 WEB 开发时,可以选择使用 Spring 的 Spring MVC 框架或集成其他 MVC 开发框架。
SpringMVC 已经成为目前最主流的 MVC 框架之一,并且随着 Spring3.0 的发布,已成为最优秀的 MVC 框架。

SpringMVC中的常用注解
@GetMapping

作用:用于建立请求URL和处理请求方法之间的对应关系
可以出现在类上,请求URL的第一级访问目录
可以出现在方法上,请求URL的第二级访问目录
value:用于指定请求的URL。它和path属性的作用是一样的
method:用于指定请求的方式
params:用于指定限制请求参数的条件
"""
  1. @Controller
  2. //@RequestMapping("SpringMVC/")
  3. public class HelloController {
  4. //请求方法为get  请求参数必须有username
  5. @RequestMapping(value = "/hello",method = RequestMethod.GET,params = {"username"})
  6. //@RequestMapping("/hello")
  7. public String sayHello(){
  8.     System.out.println("SpringMVC hello~~~");
  9.     return "success";
  10. }
  11. }
复制代码
"""
@RequestParam

作用:把请求中指定名称的参数给控制器中的形参赋值
value:请求参数的名称
required:请求参数中必须提供此参数。默认值:true,表示必须提供,如果不提供就报错。
"""
  1. @RequestMapping("/testRequestParam")
  2.         //RequestParam --更名  
  3.         // 属性  value=别名 required=必须含有的参数
  4.         public String testRequestParam(@RequestParam(value = "username") String  name){
  5.                 System.out.printf(name);
  6.                 System.out.println("testRequestParam执行了~~~");
  7.                 return "success";
  8.         }
复制代码
"""
@RequestBody

作用:用于获取请求体内容。直接使用得到key=value&key=vaule...结构的数据。get请求方式不适用
required:是否必须有请求体。当取值为true时,get请求会报错。如果取值为false,get请求得到是null
"""
  1. @RequestMapping("/testRequestBody")
  2.         //RequestBody 获取请求体中的内容  如:username=benshan&password=98989&money=200
  3.         public String testRequestBody(@RequestBody String body){
  4.                 System.out.println("testRequestBody执行了~~~");
  5.                 System.out.println(body);
  6.                 return "success";
  7.         }
复制代码
"""
@PathVariable

作用:用于绑定URL中的占位符。url中有/delete/{id},{id}就是占位符。
"""
  1.   @RequestMapping("/testPathVariable/{id}")
  2.         //PathVariable使用Restful风格,结构清晰,拓展方便
  3.         public String testPathVariable(@PathVariable(value = "id") String id){
  4.                 System.out.println("testPathVariable~~~");
  5.                 System.out.println(id);
  6.                 return "success";
  7.         }
复制代码
"""
@RequestHeader

作用:用于获取请求消息头
value 提供消息头名称
required:是否必须有此消息头
"""
  1.   @RequestMapping("/testRequestHeader")
  2.         //testRequestHeader获取请求头的值
  3.         public String testRequestHeader(@RequestHeader(value = "Accept") String header){
  4.                 System.out.println("testRequestHeader~~~");
  5.                 System.out.println(header);
  6.                 return "success";
  7.         }
复制代码
"""
@CookieValue

作用:用于把指定cookie名称的值传入控制器方法参数
  1. value:指定cookie的名称
  2. required:是否必须有此cookie
复制代码
"""
  1. @RequestMapping("/testCookieValue")
  2.         //testRequestHeader获取请求头的值
  3.         public String testCookieValue(@CookieValue(value = "JSESSIONID") String cookie){
  4.                 System.out.println("testCookieValue~~~");
  5.                 System.out.println(cookie);
  6.                 return "success";
  7.         }
复制代码
"""
@ModelAttribute

作用:可以修饰方法和参数。出现在方法上,表示当前方法会在控制器的方法执行之前执行,先执行。出现在参数上,获取指定的数据给参数赋值
value 用于获取数据的key
"""
  1. @RequestMapping("/testModelAttribute")
  2.         public String testModelAttribute(){
  3.                 System.out.println("testModelAttribute~~~");
  4.                 return "success";
  5.         }
  6.         @ModelAttribute
  7.         //在控制器执行之前  执行
  8.         public void showUser(){
  9.                 System.out.println("showUser执行了~~~");
  10.         }
复制代码
"""
@SessionAttributes

作用:用于多次执行控制器方法间的参数共享
value 用于指定存入的属性名称
type:用于指定存入的数据类型
新注解

@RequestMapping 和  @GetMapping @PostMapping 区别
@GetMapping是一个组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写。
@PostMapping是一个组合注解,是@RequestMapping(method = RequestMethod.POST)的缩写。
Spring框架

Spring是什么?

Spring是一个轻量级Java开发框架,最早有Rod Johnson创建,目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题。它是一个分层的JavaSE/JavaEE full-stack(一站式)轻量级开源框架,为开发Java应用程序提供全面的基础架构支持。Spring负责基础架构,因此Java开发者可以专注于应用程序的开发。
体系结构


核心容器(Core Container):Spring的核心容器是其他模块建立的基础,有Spring-core、Spring-beans、Spring-context、Spring-context-support和Spring-expression(String表达式语言)等模块组成
数据访问/集成(Data Access)层:数据访问/集成层由JDBC、ORM、OXM、JMS和事务模块组成。
Web层:Web层由Spring-web、Spring-webmvc、Spring-websocket和Portlet模块组成。
AOP(Aspect Oriented Programming)模块:提供了一个符合AOP要求的面向切面的编程实现,允许定义方法拦截器和切入点,将代码按照功能进行分离,以便干净地解耦。
植入(Instrumentation)模块:提供了类植入(Instrumentation)支持和类加载器的实现,可以在特定的应用服务器中使用。
消息传输(Messaging):Spring4.0以后新增了消息(Spring-messaging)模块,该模块提供了对消息传递体系结构和协议的支持。
测试(Test)模块:Spring-test模块支持使用JUnit或TestNG对Spring组件进行单元测试和集成测试。
引入jar包

"""
  1. <dependencies>
  2.                
  3.                 <dependency>
  4.                         <groupId>org.springframework</groupId>
  5.                         <artifactId>spring-context</artifactId>
  6.                         <version>5.0.11.RELEASE</version>
  7.                 </dependency>
  8.                 <dependency>
  9.                         <groupId>org.springframework</groupId>
  10.                         <artifactId>spring-test</artifactId>
  11.                         <version>5.0.11.RELEASE</version>
  12.                 </dependency>
  13.                 <dependency>
  14.                         <groupId>org.springframework</groupId>
  15.                         <artifactId>spring-tx</artifactId>
  16.                         <version>5.0.11.RELEASE</version>
  17.                 </dependency>      
  18. </dependencies>
复制代码
"""
导入约束

"""
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.            xmlns:context="http://www.springframework.org/schema/context"
  5.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  6.                         http://www.springframework.org/schema/beans/spring-beans.xsd
  7.                         http://www.springframework.org/schema/context
  8.                         http://www.springframework.org/schema/context/spring-context.xsd">
  9.           
  10.        
  11.        
  12.    
  13.         <context:component-scan base-package="com.dynamic2"></context:component-scan>
  14. </beans>
复制代码
"""
常见注解

用于创建对象

@Component:把资源让spring来管理。相当于xml中配置一个bean。value:指定bean的id,如果不指定value属性,默认bean的id是当前类的类名。首字母小写
@Controller:与@Component功能一样,一般用在表现层,便于分层
@Service:与@Component功能一样,一般用在业务层,便于分层
@Repository:与@Component功能一样,一般用于持久层,便于分层
"""
  1. /**
  2. * @Author: Promsing
  3. * @Date: @Date: 2023/7/17 - 11:34
  4. * @Description: 用于创建对象
  5. * @version: 1.0
  6. *  XML配置 <bean id="accountServiceImpl" ></bean>
  7. */
  8. @Repository("accountDao ")
  9. public class AccountDaoImpl implements IAccountDao {
  10.                         ......
  11. }
  12. @Service("accountService")
  13. public class AccountServiceImpl implements IAccountService {
  14.                         ......
  15. }
  16. @Component("accountServiceImpl")
  17. @Scope("prototype")//多例
  18. public class AccountServiceImpl2 implements IAccountService {
  19.                          ......
  20. }
复制代码
"""
用于注入数据

@Autowired:自动按照类型注入。当使用注解注入属性时,set方法可以省略。它只能注入其他bean类型。当有多个类型匹配时。使用要注入的对象变量名称作为bean的id,在spring容器中查找,找到了注入成功,找不到就报错。
@Qualifier:在自动按照类型注入的基础上,再按照Bean的id注入。它在给字段注入时不能单独使用,必须和@Autowire一起使用;但是给方法参数注入时,可以单独使用。value属性是指定Bean的id
@Resource:直接按照Bean的id注入。它也只能注入其他Bean类型。name属性是指定Bean的id
@Value:注入基本数据类型和String类型数据
"""
  1. /**
  2. * @Author: Promsing
  3. * @Date: @Date: 2023/7/17 - 11:34
  4. * @Description: 用于创建对象
  5. * @version: 1.0
  6. *  XML配置 <bean id="accountServiceImpl" ></bean>
  7. */
  8. @Component("accountServiceImpl")
  9. @Scope("prototype")//多例
  10. public class AccountServiceImpl implements IAccountService {
  11.         //注入成员变量
  12.    /* @Autowired  自动按照类型注入--寻找类型
  13.         @Qualifier("accountDao2")*/ //寻找id
  14.         //以上两个注解相加的作用等于这个
  15.         @Resource(name = "accountDao2")
  16.         private IAccountDao accountDao2;
  17.         @Override
  18.         public void saveAccount() {
  19.                 accountDao2.saveAccount();
  20.                 //System.out.println("service中的saveAccount执行了~~");
  21.         }
  22. }
复制代码
"""
用于改变作用范围

@Scope:指定Bean的作用范围。value属性指定范围的值--singleton单例,prototype多例,request作用与web应用的请求范围,session作用与web应用的会话范围,global-session作用与集群环境中会话范围
"""
  1. @Component("accountServiceImpl")
  2. @Scope("prototype")//多例
  3. public class AccountServiceImpl implements IAccountService {
  4.         ......   
  5. }
复制代码
"""
和生命周期相关(了解)

@PostConstruct:用于指定初始化方法
@PreDestroy:用于指定销毁方法
Spring5

@Configuration:用于指定当前类是一个spring配置类,当有容器时会从该类上加载注解。获取容器是使用AnnotationApplicationContext(有@Configuration注解的类.class)
@ComponentScan:用于指定spring在初始化容器时要扫描的包。作用和在spring的xml配置文件找那个的
@Bean:该注解只用用在方法上,表明使用此方法创建一个对象,并且放入spring容器中
@Import:用于导入其他配置类,解耦合
"""
  1. /**
  2. * @Author: Promsing
  3. * @Date: @Date: 2023/7/17 - 0:36
  4. * @Description: Spring配置类
  5. * @version: 1.0
  6. */
  7. @Configuration//指定当前类是一个配置类
  8. @ComponentScan("com.dynamic_transaction_anno")//用于指定spring在初始化容器时需要扫描的包
  9. @Import({JdbcConfig.class,TransactionConfig.class})//导入其他配置类
  10. @EnableTransactionManagement//开启spring注解事务的支持
  11. public class SpringConfig {
  12.         @Bean("jdbcTemplate")
  13.         public JdbcTemplate createJdbcTemplate(DataSource ds){
  14.                 return new JdbcTemplate(ds);
  15.         }
  16.         @Bean("dataSource")
  17.         public DataSource createDataSource(){
  18.                 DriverManagerDataSource dr=new DriverManagerDataSource();
  19.                 dr.setDriverClassName("com.mysql.jdbc.Driver");//com.mysql.jdbc.Driver
  20.                 dr.setUrl("jdbc:mysql//localhost:330b/eesy");
  21.                 dr.setUsername("root");
  22.                 dr.setPassword("root");
  23.                 return dr;
  24.         }
  25. }
复制代码
"""
Spring整合Junit

@RunWith:替代原有的运行器
@ContextConfiguration:指定配置文件的位置
"""
  1. @RunWith(SpringJUnit4ClassRunner.class)//替代原有运行器
  2. @ContextConfiguration(classes=SpringConfiguration.class)//指定配置类
  3. public class AccountServiceTest {
  4.         @Test
  5.         public void testFindAll(){
  6.            //执行测试方法
  7.         }
  8. }
复制代码
"""
从IOC容器中获取对象

"""
  1. /**
  2. * @Author: Promsing
  3. * @Date:@Date: 2023/7/17 - 11:22
  4. * @Description: 单元测试
  5. * @version: 1.0
  6. */
  7. @RunWith(SpringJUnit4ClassRunner.class)
  8. @ContextConfiguration(classes=SpringConfiguration.class)
  9. public class AccountServiceTest {
  10.           @Resource(name = "accountServiceImpl")
  11.           private IAccountService accountService;
  12.         @Test
  13.         //从容器中获取对象
  14.         public void test(){
  15.                 //一、获取容器
  16.                 //使用配置文件加载
  17.                 ApplicationContext ac=new ClassPathXmlApplicationContext("bean3_1.xml");
  18.                 //使用配置类加载
  19.           ///  ApplicationContext ac=new AnnotationConfigApplicationContext(SpringConfiguration.class);
  20.                 //二、获取对象
  21.                  accountService=(IAccountService)ac.getBean("accountServiceImpl",IAccountService.class);
  22.                 //三、执行方法
  23.                 List<Account> allAccounts = accountService.findAllAccount();
  24.                 for (Account allAccount : allAccounts) {
  25.                         System.out.println(allAccount);
  26.                 }
  27.         }
  28. }
复制代码
"""
Mybatis框架

MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。

Mybatis简介

官网链接:https://mybatis.org/mybatis-3/zh/index.html。
更加详细的信息可以去官网查看。
MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。
要使用 MyBatis, 只需将 mybatis-x.x.x.jar 文件置于类路径(classpath)中即可。
如果使用 Maven 来构建项目,则需将下面的依赖代码置于 pom.xml 文件中:
"""
  1. <dependency>
  2.   <groupId>org.mybatis</groupId>
  3.   <artifactId>mybatis</artifactId>
  4.   <version>x.x.x</version>
  5. </dependency>
复制代码
"""
配置步骤
1.引入Mybatis的jar包
2.编写实体类与DAO接口
3.添加主配置文件(配置mysql环境,事务类型,数据源,连接数据库的基本信息,映射文件的位置)
4.添加DAO接口的映射文件(需要指明DAO接口的位置,为每个方法做一个映射)注:所在路径在Resource文件夹下,目录路径需要DAO的层次结构一样
5.使用mybatis框架
使用步骤(所有的xml配置已配置完毕)
1.读取配置文件,可使用mybatis封装的Resources类。
2.创建SQLSessionFactory工厂
3.使用工厂生产SQLsession对象
4.使用SQLSession创建DAO接口的代理对象
5.使用代理对象执行方法
6.提交事务,释放资源
基础数据

实体类
"""
  1. public class User implements Serializable {
  2.         /**
  3.          * Java实体类为什么要实现Serializable接口
  4.          *  1.用于序列化与反序列化--一个类只有实现了Serializable接口,它的对象才能被序列化。
  5.          *  2.Serializable接口就是Java提供用来进行高效率的异地共享实例对象的机制,实现这个接口即可。
  6.          */
  7.         private Integer id;
  8.         private String username;
  9.         private Date birthday;
  10.         private String sex;
  11.         private String address;
  12.         public Integer getId() {
  13.                 return id;
  14.         }
  15.         public void setId(Integer id) {
  16.                 this.id = id;
  17.         }
  18.         public String getUsername() {
  19.                 return username;
  20.         }
  21.         public void setUsername(String username) {
  22.                 this.username = username;
  23.         }
  24.         public Date getBirthday() {
  25.                 return birthday;
  26.         }
  27.         public void setBirthday(Date birthday) {
  28.                 this.birthday = birthday;
  29.         }
  30.         public String getSex() {
  31.                 return sex;
  32.         }
  33.         public void setSex(String sex) {
  34.                 this.sex = sex;
  35.         }
  36.         public String getAddress() {
  37.                 return address;
  38.         }
  39.         public void setAddress(String address) {
  40.                 this.address = address;
  41.         }
  42.         @Override
  43.         public String toString() {
  44.                 return "User{" +
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.            xmlns:context="http://www.springframework.org/schema/context"
  48.            xmlns:aop="http://www.springframework.org/schema/aop"
  49.            xmlns:tx="http://www.springframework.org/schema/tx"
  50.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  51.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  52.                    http://www.springframework.org/schema/context
  53.                         http://www.springframework.org/schema/context/spring-context.xsd
  54.                         http://www.springframework.org/schema/aop
  55.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  56.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  57.         <context:component-scan base-package="com.dynamic">
  58.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  59.         </context:component-scan>
  60. </beans>"id=" + id +
  61. <beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans>", username='" + username + '\'' +
  77. <beans xmlns="http://www.springframework.org/schema/beans"
  78.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.            xmlns:context="http://www.springframework.org/schema/context"
  80.            xmlns:aop="http://www.springframework.org/schema/aop"
  81.            xmlns:tx="http://www.springframework.org/schema/tx"
  82.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  83.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  84.                    http://www.springframework.org/schema/context
  85.                         http://www.springframework.org/schema/context/spring-context.xsd
  86.                         http://www.springframework.org/schema/aop
  87.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  88.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  89.         <context:component-scan base-package="com.dynamic">
  90.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  91.         </context:component-scan>
  92. </beans>", birthday=" + birthday +
  93. <beans xmlns="http://www.springframework.org/schema/beans"
  94.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  95.            xmlns:context="http://www.springframework.org/schema/context"
  96.            xmlns:aop="http://www.springframework.org/schema/aop"
  97.            xmlns:tx="http://www.springframework.org/schema/tx"
  98.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  99.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  100.                    http://www.springframework.org/schema/context
  101.                         http://www.springframework.org/schema/context/spring-context.xsd
  102.                         http://www.springframework.org/schema/aop
  103.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  104.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  105.         <context:component-scan base-package="com.dynamic">
  106.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  107.         </context:component-scan>
  108. </beans>", sex='" + sex + '\'' +
  109. <beans xmlns="http://www.springframework.org/schema/beans"
  110.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  111.            xmlns:context="http://www.springframework.org/schema/context"
  112.            xmlns:aop="http://www.springframework.org/schema/aop"
  113.            xmlns:tx="http://www.springframework.org/schema/tx"
  114.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  115.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  116.                    http://www.springframework.org/schema/context
  117.                         http://www.springframework.org/schema/context/spring-context.xsd
  118.                         http://www.springframework.org/schema/aop
  119.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  120.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  121.         <context:component-scan base-package="com.dynamic">
  122.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  123.         </context:component-scan>
  124. </beans>", address='" + address + '\'' +
  125. <beans xmlns="http://www.springframework.org/schema/beans"
  126.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  127.            xmlns:context="http://www.springframework.org/schema/context"
  128.            xmlns:aop="http://www.springframework.org/schema/aop"
  129.            xmlns:tx="http://www.springframework.org/schema/tx"
  130.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  131.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  132.                    http://www.springframework.org/schema/context
  133.                         http://www.springframework.org/schema/context/spring-context.xsd
  134.                         http://www.springframework.org/schema/aop
  135.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  136.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  137.         <context:component-scan base-package="com.dynamic">
  138.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  139.         </context:component-scan>
  140. </beans>'}';
  141.         }
复制代码
"""
DAO层的接口

"""
  1. public interface IUserDao {
  2.         /**
  3.          * 查询所有
  4.          * @return 所有的User信息
  5.          */
  6.         //@Select("select * from User")
  7.         List<User> findAll();
  8.         /**
  9.          * 保存操作
  10.          * @param user
  11.          */
  12.         //@Insert("insert into User(username,address,sex,birthday)values()")
  13.         void saveUser(User user);
  14.         /**
  15.          * 更改操作
  16.          */
  17.         void updateUser(User user);
  18.         /**
  19.          * 删除操作
  20.          * @param i
  21.          */
  22.         void deleteUser(Integer i);
  23.         /**
  24.          * 根据id查询单个用户
  25.          * @param id
  26.          * @return
  27.          */
  28.         User findById(Integer id);
  29.         /**
  30.          * 根据名称模糊查询
  31.          * @param name
  32.          * @return
  33.          */
  34.         List<User> findByName(String name);
  35.         /**
  36.          * 查询总用户数
  37.          * @return
  38.          */
  39.         int findTotal();
  40. }
复制代码
"""
主配置文件

"""
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE configuration
  3.                 PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4.                 "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6.        
  7.         <environments default="mysql">
  8.                
  9.                 <environment id="mysql">
  10.                        
  11.                         <transactionManager type="JDBC"></transactionManager>
  12.                        
  13.                         <dataSource type="POOLED">
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.            xmlns:context="http://www.springframework.org/schema/context"
  17.            xmlns:aop="http://www.springframework.org/schema/aop"
  18.            xmlns:tx="http://www.springframework.org/schema/tx"
  19.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  20.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  21.                    http://www.springframework.org/schema/context
  22.                         http://www.springframework.org/schema/context/spring-context.xsd
  23.                         http://www.springframework.org/schema/aop
  24.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  25.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  26.         <context:component-scan base-package="com.dynamic">
  27.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  28.         </context:component-scan>
  29. </beans>
  30. <beans xmlns="http://www.springframework.org/schema/beans"
  31.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  32.            xmlns:context="http://www.springframework.org/schema/context"
  33.            xmlns:aop="http://www.springframework.org/schema/aop"
  34.            xmlns:tx="http://www.springframework.org/schema/tx"
  35.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  36.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  37.                    http://www.springframework.org/schema/context
  38.                         http://www.springframework.org/schema/context/spring-context.xsd
  39.                         http://www.springframework.org/schema/aop
  40.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  41.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  42.         <context:component-scan base-package="com.dynamic">
  43.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  44.         </context:component-scan>
  45. </beans><property name="driver" value="com.mysql.jdbc.Driver"/>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans><property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.            xmlns:context="http://www.springframework.org/schema/context"
  65.            xmlns:aop="http://www.springframework.org/schema/aop"
  66.            xmlns:tx="http://www.springframework.org/schema/tx"
  67.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  68.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  69.                    http://www.springframework.org/schema/context
  70.                         http://www.springframework.org/schema/context/spring-context.xsd
  71.                         http://www.springframework.org/schema/aop
  72.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  73.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  74.         <context:component-scan base-package="com.dynamic">
  75.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  76.         </context:component-scan>
  77. </beans><property name="username" value="root"/>
  78. <beans xmlns="http://www.springframework.org/schema/beans"
  79.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  80.            xmlns:context="http://www.springframework.org/schema/context"
  81.            xmlns:aop="http://www.springframework.org/schema/aop"
  82.            xmlns:tx="http://www.springframework.org/schema/tx"
  83.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  84.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  85.                    http://www.springframework.org/schema/context
  86.                         http://www.springframework.org/schema/context/spring-context.xsd
  87.                         http://www.springframework.org/schema/aop
  88.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  89.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  90.         <context:component-scan base-package="com.dynamic">
  91.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  92.         </context:component-scan>
  93. </beans><property name="password" value="root"/>
  94.                         </dataSource>
  95.                 </environment>
  96.         </environments>
  97.        
  98.         <mappers>
  99.                 <mapper resource="com/dynamic_basics/dao/IUserDao.xml"></mapper>
  100.         </mappers>
  101.        
  102.    
  103. </configuration>
复制代码
"""
子配置文件

"""
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3.                 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4.                 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.dynamic_basics.dao.IUserDao">
  6.        
  7.         <resultMap id="userMap" type="com.dynamic_basics.domain.User">
  8.                
  9.                 <id property="userId" column="id"></id>
  10.                
  11.                 <result property="userName" column="username"></result>
  12.                 <result property="userAddress" column="address"></result>
  13.                 <result property="userSex" column="sex"></result>
  14.                 <result property="userBirthday" column="birthday"></result>
  15.         </resultMap>
  16.        
  17.         <select id="findAl l" resultType="com.dynamic_basics.domain.User" resultMap="userMap">
  18.                 select * from user
  19.         </select>
  20.        
  21.         <insert id="saveUser" parameterType="com.dynamic_basics.domain.User">
  22.                
  23.                 insert into user(username,address,sex,birthday)values(#{username},#{address},#{sex},#{birthday});
  24.         </insert>
  25.        
  26.         <insert id="updateUser" parameterType="com.dynamic_basics.domain.User">
  27.            update user set username=#{username},address=#{address},sex=#{sex},birthday=#{birthday} where id=#{id}
  28.         </insert>
  29.        
  30.         <delete id="deleteUser" parameterType="int">
  31.                 delete from User where id=#{id}
  32.         </delete>
  33.        
  34.         <select id="findById" parameterType="int" resultType="com.dynamic_basics.domain.User">
  35.                 select * from user where id=#{id}
  36.         </select>
  37.        
  38.         <select id="findByName" resultType="com.dynamic_basics.domain.User" parameterType="String">
  39.                 select * from user where username like #{name}
  40.         </select>
  41.        
  42.         <select id="findTotal" resultType="int">
  43.                 SELECT COUNT(id) FROM `user`;
  44.         </select>
  45. </mapper>
复制代码
"""
测试类

"""
  1. /**
  2. * @Author: Promsing
  3. * @Date: @Date: 2023/7/17 - 8:58
  4. * @Description: 描述 形容
  5. * @version: 1.0
  6. */
  7. public class MyBatisTest {
  8.         private InputStream in;
  9.         private SqlSession sqlSession;
  10.         private IUserDao userDao;
  11.         @Before
  12.         public void init()throws Exception{
  13.                 //1.读取配置文件  Resources是myBatis封装的类
  14.                 in= Resources.getResourceAsStream("SqlMapConfig.xml");
  15.                 //2.创建SQLSessionFactory工厂
  16.                 //  SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(is);
  17.                 SqlSessionFactoryBuilder builder=new SqlSessionFactoryBuilder();
  18.                 SqlSessionFactory factory=builder.build(in);
  19.                 //3.使用工厂生产SQLSession对象
  20.                 sqlSession = factory.openSession();
  21.                 //4.使用SQLSession创建DAO接口的代理对象
  22.                  userDao = sqlSession.getMapper(IUserDao.class);
  23.         }
  24.         @After
  25.         public void destory()throws Exception{
  26.                 //6.释放资源
  27.                 //提交事务
  28.                 sqlSession.commit();
  29.                 sqlSession.close();
  30.                 in.close();
  31.         }
  32.         //入门案例
  33.         /**
  34.          * 查询操作
  35.          */
  36.         @Test
  37.    public void selectUser(){
  38.                 //初始化资源-使用注解Before
  39.                 //5.使用代理对象执行方法
  40.                 List<User> all = userDao.findAll();
  41.                 for (User user : all) {
  42.                         System.out.println(user);
  43.                 }
  44.                 //释放资源-使用注解After
  45.         }
  46.         /**
  47.          * 测试保存
  48.          */
  49.         @Test
  50.         public void testSave() {
  51.                 User user=new User();
  52.                 user.setUsername("mybatis");
  53.                 user.setAddress("北京市延庆区");
  54.                 user.setSex("女");
  55.                 user.setBirthday(new Date());
  56.                 //初始化资源-使用注解Before
  57.                 //5.使用代理对象执行方法
  58.                 userDao.saveUser(user);
  59.                 //释放资源-使用注解After
  60.         }
  61.         /**
  62.          * 测试修改
  63.          */
  64.         @Test
  65.         public void testUpdate() {
  66.                 User user=new User();
  67.                 user.setId(50);
  68.                 user.setUsername("mybatis_plus");
  69.                 user.setAddress("北京市安次");
  70.                 user.setSex("男");
  71.                 user.setBirthday(new Date());
  72.                 //初始化资源-使用注解Before
  73.                 //5.使用代理对象执行方法
  74.                 userDao.updateUser(user);
  75.                 //释放资源-使用注解After
  76.         }
  77.         /**
  78.          * 测试删除
  79.          */
  80.         @Test
  81.         public void testDelete() {
  82.                 //初始化资源-使用注解Before
  83.                 //5.使用代理对象执行方法
  84.                 userDao.deleteUser(50);
  85.                 //释放资源-使用注解After
  86.         }
  87.         /**
  88.          * 查询单个人员信息
  89.          */
  90.         @Test
  91.         public void testFindById() {
  92.                 //初始化资源-使用注解Before
  93.                 //5.使用代理对象执行方法
  94.                 User user=userDao.findById(49);
  95.                 System.out.println(user);
  96.                 //释放资源-使用注解After
  97.         }
  98.         /**
  99.          * 模糊查询
  100.          */
  101.         @Test
  102.         public void testFindByName() {
  103.                 //初始化资源-使用注解Before
  104.                 //5.使用代理对象执行方法
  105.                 List<User> users=userDao.findByName("%王%");
  106.            users.forEach(i-> System.out.println(i));
  107.                 //释放资源-使用注解After
  108.         }
  109.         /**
  110.          * 测试查询总记录条数
  111.          */
  112.         @Test
  113.         public void testFindTotal() {
  114.                 //初始化资源-使用注解Before
  115.                 //5.使用代理对象执行方法
  116.                 int total=userDao.findTotal();
  117.                 System.out.println(total);
  118.                 //释放资源-使用注解After
  119.         }
  120. }
复制代码
"""
总结
Mybatis其实使用的方法很简单,需要多记住一些配置,当配置做好了,使用的时候很简单。Mybatis框架将JDBC中复杂的注册驱动、获取连接,使用不同的服务类---
(DriverManager,Connection,Statement,ResultSet)都封装了。其实框架的学习就是了解框架、熟悉配置,使用框架的阶段。
配置顶层结构:

常用标签设置

具体配置的详解请去mybatis官网
整合思路

1.先搭建整合的环境
2.把Spring的配置搭建完成
3.再使用Spring整合SpringMVC框架
4.最后使用Spring整合Mybatis框架
设计数据库
"""
  1. CREATE DATABASE ssm;
  2. USE ssm;
  3. CREATE TABLE account ( id INT PRIMARY KEY auto_increment, NAME VARCHAR ( 20 ), money DOUBLE );
复制代码
"""
搭建环境,选择maven工程,选择骨架webapp

导入依赖
"""
  1. <name>SSM Maven Webapp</name>
  2.   
  3.   <url>http://www.example.com</url>
  4.   <properties>
  5.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  6.         <maven.compiler.source>1.7</maven.compiler.source>
  7.         <maven.compiler.target>1.7</maven.compiler.target>
  8.   
  9.         <spring.version>5.0.2.RELEASE</spring.version>
  10.         <slf4j.version>1.6.6</slf4j.version>
  11.         <log4j.version>1.2.12</log4j.version>
  12.         <mysql.version>5.1.6</mysql.version>
  13.         <mybatis.version>3.4.5</mybatis.version>
  14.   </properties>
  15.   <dependencies>
  16.         <dependency>
  17.           <groupId>junit</groupId>
  18.           <artifactId>junit</artifactId>
  19.           <version>4.11</version>
  20.           <scope>test</scope>
  21.         </dependency>
  22.        
  23.         <dependency>
  24.           <groupId>org.aspectj</groupId>
  25.           <artifactId>aspectjweaver</artifactId>
  26.           <version>1.6.8</version>
  27.         </dependency>
  28.         <dependency>
  29.           <groupId>org.springframework</groupId>
  30.           <artifactId>spring-aop</artifactId>
  31.           <version>5.0.2.RELEASE</version>
  32.         </dependency>
  33.         <dependency>
  34.         <groupId>org.springframework</groupId>
  35.         <artifactId>spring-context</artifactId>
  36.           <version>5.0.2.RELEASE</version>
  37.         </dependency>
  38.         <dependency>
  39.         <groupId>org.springframework</groupId>
  40.           <artifactId>spring-web</artifactId>
  41.           <version>5.0.2.RELEASE</version>
  42.         </dependency>
  43.         <dependency>
  44.           <groupId>org.springframework</groupId>
  45.           <artifactId>spring-webmvc</artifactId>
  46.           <version>5.0.2.RELEASE</version>
  47.         </dependency> <dependency>
  48.         <groupId>org.springframework</groupId>
  49.         <artifactId>spring-test</artifactId>
  50.         <version>5.0.2.RELEASE</version>
  51.   </dependency> <dependency>
  52.         <groupId>org.springframework</groupId>
  53.         <artifactId>spring-tx</artifactId>
  54.         <version>5.0.2.RELEASE</version>
  55.   </dependency> <dependency>
  56.         <groupId>org.springframework</groupId>
  57.         <artifactId>spring-jdbc</artifactId>
  58.         <version>5.0.2.RELEASE</version>
  59.   </dependency>
  60.         <dependency>
  61.           <groupId>junit</groupId>
  62.           <artifactId>junit</artifactId>
  63.           <version>4.12</version>
  64.         <scope>compile</scope>
  65.         </dependency>
  66.         <dependency>
  67.           <groupId>mysql</groupId>
  68.           <artifactId>mysql-connector-java</artifactId>
  69.           <version>${mysql.version}</version>
  70.         </dependency>
  71.         <dependency>
  72.           <groupId>javax.servlet</groupId>
  73.           <artifactId>servlet-api</artifactId>
  74.           <version>2.5</version>
  75.           <scope>provided</scope>
  76.         </dependency> <dependency>
  77.         <groupId>javax.servlet.jsp</groupId>
  78.         <artifactId>jsp-api</artifactId>
  79.         <version>2.0</version>
  80.         <scope>provided</scope>
  81.   </dependency>
  82.         <dependency>
  83.           <groupId>jstl</groupId>
  84.           <artifactId>jstl</artifactId>
  85.           <version>1.2</version>
  86.         </dependency>
  87.        
  88.         <dependency>
  89.           <groupId>log4j</groupId>
  90.           <artifactId>log4j</artifactId>
  91.           <version>${log4j.version}</version>
  92.         </dependency>
  93.         <dependency>
  94.         <groupId>org.slf4j</groupId>
  95.           <artifactId>slf4j-api</artifactId>
  96.           <version>${slf4j.version}</version>
  97.         </dependency> <dependency>
  98.         <groupId>org.slf4j</groupId>
  99.         <artifactId>slf4j-log4j12</artifactId>
  100.         <version>${slf4j.version}</version>
  101.   </dependency>
  102.        
  103.         <dependency>
  104.           <groupId>org.mybatis</groupId>
  105.           <artifactId>mybatis</artifactId>
  106.           <version>${mybatis.version}</version>
  107.         </dependency>
  108.         <dependency>
  109.           <groupId>org.mybatis</groupId>
  110.           <artifactId>mybatis-spring</artifactId>
  111.           <version>1.3.0</version>
  112.         </dependency>
  113.         <dependency>
  114.           <groupId>c3p0</groupId>
  115.           <artifactId>c3p0</artifactId>
  116.           <version>0.9.1.2</version>
  117.           <type>jar</type>
  118.           <scope>compile</scope>
  119.         </dependency>
  120.   </dependencies>
复制代码
"""
创建目录结构,创建domain,controller,service,dao
web依赖于service,service依赖于dao,dao依赖于domain


domain
"""
  1. package com.dynamic.domain;
  2. import java.io.Serializable;
  3. /**
  4. * @Author: Promsing
  5. * @Date: 2023/7/17 - 17:44
  6. * @Description: 实体类-Account
  7. * @version: 1.0
  8. */
  9. public class Account implements Serializable {
  10.         private Integer id;
  11.         private String name;
  12.         private Double money;
  13.         public Integer getId() {
  14.                 return id;
  15.         }
  16.         public void setId(Integer id) {
  17.                 this.id = id;
  18.         }
  19.         public String getName() {
  20.                 return name;
  21.         }
  22.         public void setName(String name) {
  23.                 this.name = name;
  24.         }
  25.         public Double getMoney() {
  26.                 return money;
  27.         }
  28.         public void setMoney(Double money) {
  29.                 this.money = money;
  30.         }
  31.         @Override
  32.         public String toString() {
  33.                 return "Account{" +
  34. <beans xmlns="http://www.springframework.org/schema/beans"
  35.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  36.            xmlns:context="http://www.springframework.org/schema/context"
  37.            xmlns:aop="http://www.springframework.org/schema/aop"
  38.            xmlns:tx="http://www.springframework.org/schema/tx"
  39.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  40.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  41.                    http://www.springframework.org/schema/context
  42.                         http://www.springframework.org/schema/context/spring-context.xsd
  43.                         http://www.springframework.org/schema/aop
  44.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  45.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  46.         <context:component-scan base-package="com.dynamic">
  47.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  48.         </context:component-scan>
  49. </beans>"id=" + id +
  50. <beans xmlns="http://www.springframework.org/schema/beans"
  51.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  52.            xmlns:context="http://www.springframework.org/schema/context"
  53.            xmlns:aop="http://www.springframework.org/schema/aop"
  54.            xmlns:tx="http://www.springframework.org/schema/tx"
  55.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  56.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  57.                    http://www.springframework.org/schema/context
  58.                         http://www.springframework.org/schema/context/spring-context.xsd
  59.                         http://www.springframework.org/schema/aop
  60.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  61.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  62.         <context:component-scan base-package="com.dynamic">
  63.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  64.         </context:component-scan>
  65. </beans>", name='" + name + '\'' +
  66. <beans xmlns="http://www.springframework.org/schema/beans"
  67.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.            xmlns:context="http://www.springframework.org/schema/context"
  69.            xmlns:aop="http://www.springframework.org/schema/aop"
  70.            xmlns:tx="http://www.springframework.org/schema/tx"
  71.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  72.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  73.                    http://www.springframework.org/schema/context
  74.                         http://www.springframework.org/schema/context/spring-context.xsd
  75.                         http://www.springframework.org/schema/aop
  76.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  77.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  78.         <context:component-scan base-package="com.dynamic">
  79.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  80.         </context:component-scan>
  81. </beans>", money=" + money +
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.            xmlns:context="http://www.springframework.org/schema/context"
  85.            xmlns:aop="http://www.springframework.org/schema/aop"
  86.            xmlns:tx="http://www.springframework.org/schema/tx"
  87.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  88.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  89.                    http://www.springframework.org/schema/context
  90.                         http://www.springframework.org/schema/context/spring-context.xsd
  91.                         http://www.springframework.org/schema/aop
  92.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  93.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  94.         <context:component-scan base-package="com.dynamic">
  95.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  96.         </context:component-scan>
  97. </beans>'}';
  98.         }
  99. }
复制代码
"""
Controller层
"""
  1. package com.dynamic.controller;
  2. /**
  3. * @Author: Promsing
  4. * @Date: 2023/7/17 - 17:50
  5. * @Description: Web层账户
  6. * @version: 1.0
  7. */
  8. @Controller
  9. @RequestMapping("/account")
  10. public class AccountController {
  11.         @Autowired
  12.         private AccountService service;
  13.         //需要加 /
  14.         @GetMapping("/findAll")
  15.         public String findAll(Model model){
  16.                 System.out.println("表现层查询所有信息!");
  17.                 //调用Service方法
  18.                 List<Account> all = service.findAll();
  19.                 for (Account account : all) {
  20.                         System.out.println(account);
  21.                 }
  22.                 model.addAttribute("all",all);
  23.                 return "success";
  24.         }
  25.         @PostMapping("/save")
  26.         public String save(Account account){
  27.           service.saveAccount(account);
  28.                 return "success";
  29.         }
  30. }
复制代码
"""
service层
"""
  1. public interface AccountService {
  2.         /**
  3.          * 查询所有
  4.          * @return
  5.          */
  6.         public List<Account> findAll();
  7.         /**
  8.          * 保存账户信息
  9.          * @param account
  10.          */
  11.         public void saveAccount(Account account);
  12. }
  13. @Service("accountService")
  14. public class AccountServiceImpl implements AccountService {
  15.         @Autowired
  16.         private AccountDao dao;
  17.         @Override
  18.         public List<Account> findAll() {
  19.                 System.out.println("业务层:查询所有信息!");
  20.                 return  dao.findAll();
  21.         }
  22.         @Override
  23.         public void saveAccount(Account account) {
  24.                 System.out.println("业务层:保存账户。。。");
  25.                 dao.saveAccount(account);
  26.         }
  27. }
复制代码
"""
dao层
"""
  1. /**
  2. * @Author: Promsing
  3. * @Date: 2023/7/17 - 17:46
  4. * @Description: DAO层  使用注解
  5. * @version: 1.0
  6. */
  7. @Repository
  8. public interface AccountDao {
  9.         /**
  10.          * 查询所有
  11.          * @return
  12.          */
  13.         @Select("select * from account")
  14.         public List<Account> findAll();
  15.         /**
  16.          * 保存账户信息
  17.          * @param account
  18.          */
  19.         @Insert("insert into account (name,money) values(#{name},#{money})")
  20.         public void saveAccount(Account account);
  21. }
复制代码
"""
index页面
"""
  1. <%--
  2.   Created by IntelliJ IDEA.
  3.   User: Administrator
  4.   Date: 2023/7/17
  5.   Time: 19:00
  6.   To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
  9. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  10. <html>
  11. <head>
  12.         <title>首页</title>
  13. </head>
  14. <body>
  15.         <a target="_blank" href="https://www.cnblogs.com/account/findAll">测试查询</a>
  16.         <form action="account/save" method="post">
  17.                 姓名:<input type="text" name="name"><br/>
  18.                 金额:<input type="text" name="money"><br/>
  19.                 <input type="submit" value="保存"><br/>
  20.         </form>
  21. </body>
  22. </html>
复制代码
"""
Success页面
"""
  1. <%--
  2.   Created by IntelliJ IDEA.
  3.   User: Administrator
  4.   Date: 2023/7/17
  5.   Time: 19:10
  6.   To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
  9. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  10. <html>
  11. <head>
  12.         <title>成功页面</title>
  13. </head>
  14. <body>
  15.         <h1>成功页面</h1>
  16.         ${all}
  17.         <br/>
  18.         <c:forEach items="${all}" var="account">
  19.                 ${account.name}
  20.                 ${account.money}
  21.         </c:forEach>
  22. </body>
  23. </html>
复制代码
"""
编写Spring框架
applicationContext文件

"""
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans>
复制代码
"""
Spring整合SpringMVC框架

编写SpringMVC框架

web.xml
"""
  1.         Archetype Created Web Application<beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans>dispatcherServlet                org.springframework.web.servlet.DispatcherServlet<beans xmlns="http://www.springframework.org/schema/beans"
  17.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.            xmlns:context="http://www.springframework.org/schema/context"
  19.            xmlns:aop="http://www.springframework.org/schema/aop"
  20.            xmlns:tx="http://www.springframework.org/schema/tx"
  21.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  22.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  23.                    http://www.springframework.org/schema/context
  24.                         http://www.springframework.org/schema/context/spring-context.xsd
  25.                         http://www.springframework.org/schema/aop
  26.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  27.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  28.         <context:component-scan base-package="com.dynamic">
  29.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  30.         </context:component-scan>
  31. </beans>                        contextConfigLocation                        classpath:springmvc.xml<beans xmlns="http://www.springframework.org/schema/beans"
  32.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33.            xmlns:context="http://www.springframework.org/schema/context"
  34.            xmlns:aop="http://www.springframework.org/schema/aop"
  35.            xmlns:tx="http://www.springframework.org/schema/tx"
  36.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  37.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  38.                    http://www.springframework.org/schema/context
  39.                         http://www.springframework.org/schema/context/spring-context.xsd
  40.                         http://www.springframework.org/schema/aop
  41.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  42.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  43.         <context:component-scan base-package="com.dynamic">
  44.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  45.         </context:component-scan>
  46. </beans>                1<beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans>dispatcherServlet                /<beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans>        characterEncodingFilter                org.springframework.web.filter.CharacterEncodingFilter<beans xmlns="http://www.springframework.org/schema/beans"
  77.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  78.            xmlns:context="http://www.springframework.org/schema/context"
  79.            xmlns:aop="http://www.springframework.org/schema/aop"
  80.            xmlns:tx="http://www.springframework.org/schema/tx"
  81.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  82.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  83.                    http://www.springframework.org/schema/context
  84.                         http://www.springframework.org/schema/context/spring-context.xsd
  85.                         http://www.springframework.org/schema/aop
  86.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  87.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  88.         <context:component-scan base-package="com.dynamic">
  89.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  90.         </context:component-scan>
  91. </beans>        encoding                        UTF-8<beans xmlns="http://www.springframework.org/schema/beans"
  92.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.            xmlns:context="http://www.springframework.org/schema/context"
  94.            xmlns:aop="http://www.springframework.org/schema/aop"
  95.            xmlns:tx="http://www.springframework.org/schema/tx"
  96.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  97.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  98.                    http://www.springframework.org/schema/context
  99.                         http://www.springframework.org/schema/context/spring-context.xsd
  100.                         http://www.springframework.org/schema/aop
  101.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  102.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  103.         <context:component-scan base-package="com.dynamic">
  104.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  105.         </context:component-scan>
  106. </beans>                characterEncodingFilter                /*       
复制代码
"""
Springmvc.xml
"""
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  17.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.            xmlns:context="http://www.springframework.org/schema/context"
  19.            xmlns:aop="http://www.springframework.org/schema/aop"
  20.            xmlns:tx="http://www.springframework.org/schema/tx"
  21.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  22.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  23.                    http://www.springframework.org/schema/context
  24.                         http://www.springframework.org/schema/context/spring-context.xsd
  25.                         http://www.springframework.org/schema/aop
  26.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  27.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  28.         <context:component-scan base-package="com.dynamic">
  29.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  30.         </context:component-scan>
  31. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  32.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33.            xmlns:context="http://www.springframework.org/schema/context"
  34.            xmlns:aop="http://www.springframework.org/schema/aop"
  35.            xmlns:tx="http://www.springframework.org/schema/tx"
  36.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  37.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  38.                    http://www.springframework.org/schema/context
  39.                         http://www.springframework.org/schema/context/spring-context.xsd
  40.                         http://www.springframework.org/schema/aop
  41.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  42.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  43.         <context:component-scan base-package="com.dynamic">
  44.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  45.         </context:component-scan>
  46. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans>               
复制代码
"""
整合SpringMVC框架

在Controller中能够成功调用service对象中的方法


在web.xml中配置ContextLoaderListener监听器。加载applicationContext.xml文件
在项目启动的时候,就去加载applicationContext.xml的配置文件,在web.xml中配置ContextLoaderListener监听器。(该监听器只能加载WEB-INF目录下的applicationContext.xml的配置文件)
"""
  1.         Archetype Created Web Application<beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans>org.springframework.web.context.ContextLoaderListener<beans xmlns="http://www.springframework.org/schema/beans"
  17.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.            xmlns:context="http://www.springframework.org/schema/context"
  19.            xmlns:aop="http://www.springframework.org/schema/aop"
  20.            xmlns:tx="http://www.springframework.org/schema/tx"
  21.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  22.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  23.                    http://www.springframework.org/schema/context
  24.                         http://www.springframework.org/schema/context/spring-context.xsd
  25.                         http://www.springframework.org/schema/aop
  26.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  27.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  28.         <context:component-scan base-package="com.dynamic">
  29.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  30.         </context:component-scan>
  31. </beans>        contextConfigLocation                classpath:applicationContext.xml<beans xmlns="http://www.springframework.org/schema/beans"
  32.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33.            xmlns:context="http://www.springframework.org/schema/context"
  34.            xmlns:aop="http://www.springframework.org/schema/aop"
  35.            xmlns:tx="http://www.springframework.org/schema/tx"
  36.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  37.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  38.                    http://www.springframework.org/schema/context
  39.                         http://www.springframework.org/schema/context/spring-context.xsd
  40.                         http://www.springframework.org/schema/aop
  41.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  42.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  43.         <context:component-scan base-package="com.dynamic">
  44.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  45.         </context:component-scan>
  46. </beans>        dispatcherServlet                org.springframework.web.servlet.DispatcherServlet<beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans>                        contextConfigLocation                        classpath:springmvc.xml<beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans>                1<beans xmlns="http://www.springframework.org/schema/beans"
  77.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  78.            xmlns:context="http://www.springframework.org/schema/context"
  79.            xmlns:aop="http://www.springframework.org/schema/aop"
  80.            xmlns:tx="http://www.springframework.org/schema/tx"
  81.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  82.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  83.                    http://www.springframework.org/schema/context
  84.                         http://www.springframework.org/schema/context/spring-context.xsd
  85.                         http://www.springframework.org/schema/aop
  86.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  87.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  88.         <context:component-scan base-package="com.dynamic">
  89.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  90.         </context:component-scan>
  91. </beans>dispatcherServlet                /<beans xmlns="http://www.springframework.org/schema/beans"
  92.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.            xmlns:context="http://www.springframework.org/schema/context"
  94.            xmlns:aop="http://www.springframework.org/schema/aop"
  95.            xmlns:tx="http://www.springframework.org/schema/tx"
  96.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  97.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  98.                    http://www.springframework.org/schema/context
  99.                         http://www.springframework.org/schema/context/spring-context.xsd
  100.                         http://www.springframework.org/schema/aop
  101.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  102.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  103.         <context:component-scan base-package="com.dynamic">
  104.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  105.         </context:component-scan>
  106. </beans>        characterEncodingFilter                org.springframework.web.filter.CharacterEncodingFilter<beans xmlns="http://www.springframework.org/schema/beans"
  107.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  108.            xmlns:context="http://www.springframework.org/schema/context"
  109.            xmlns:aop="http://www.springframework.org/schema/aop"
  110.            xmlns:tx="http://www.springframework.org/schema/tx"
  111.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  112.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  113.                    http://www.springframework.org/schema/context
  114.                         http://www.springframework.org/schema/context/spring-context.xsd
  115.                         http://www.springframework.org/schema/aop
  116.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  117.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  118.         <context:component-scan base-package="com.dynamic">
  119.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  120.         </context:component-scan>
  121. </beans>        encoding                        UTF-8<beans xmlns="http://www.springframework.org/schema/beans"
  122.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.            xmlns:context="http://www.springframework.org/schema/context"
  124.            xmlns:aop="http://www.springframework.org/schema/aop"
  125.            xmlns:tx="http://www.springframework.org/schema/tx"
  126.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  127.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  128.                    http://www.springframework.org/schema/context
  129.                         http://www.springframework.org/schema/context/spring-context.xsd
  130.                         http://www.springframework.org/schema/aop
  131.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  132.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  133.         <context:component-scan base-package="com.dynamic">
  134.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  135.         </context:component-scan>
  136. </beans>                characterEncodingFilter                /*       
复制代码
"""
Spring整合Mybatis框架

编写Mybatis框架

在web项目中编写SqlMapConfig.xml的配置文件,编写核心配置文件(AccountDAO接口的方法上添加注解,编写Sql语句)
"""
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  17.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.            xmlns:context="http://www.springframework.org/schema/context"
  19.            xmlns:aop="http://www.springframework.org/schema/aop"
  20.            xmlns:tx="http://www.springframework.org/schema/tx"
  21.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  22.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  23.                    http://www.springframework.org/schema/context
  24.                         http://www.springframework.org/schema/context/spring-context.xsd
  25.                         http://www.springframework.org/schema/aop
  26.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  27.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  28.         <context:component-scan base-package="com.dynamic">
  29.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  30.         </context:component-scan>
  31. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  32.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33.            xmlns:context="http://www.springframework.org/schema/context"
  34.            xmlns:aop="http://www.springframework.org/schema/aop"
  35.            xmlns:tx="http://www.springframework.org/schema/tx"
  36.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  37.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  38.                    http://www.springframework.org/schema/context
  39.                         http://www.springframework.org/schema/context/spring-context.xsd
  40.                         http://www.springframework.org/schema/aop
  41.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  42.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  43.         <context:component-scan base-package="com.dynamic">
  44.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  45.         </context:component-scan>
  46. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  77.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  78.            xmlns:context="http://www.springframework.org/schema/context"
  79.            xmlns:aop="http://www.springframework.org/schema/aop"
  80.            xmlns:tx="http://www.springframework.org/schema/tx"
  81.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  82.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  83.                    http://www.springframework.org/schema/context
  84.                         http://www.springframework.org/schema/context/spring-context.xsd
  85.                         http://www.springframework.org/schema/aop
  86.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  87.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  88.         <context:component-scan base-package="com.dynamic">
  89.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  90.         </context:component-scan>
  91. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  92.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.            xmlns:context="http://www.springframework.org/schema/context"
  94.            xmlns:aop="http://www.springframework.org/schema/aop"
  95.            xmlns:tx="http://www.springframework.org/schema/tx"
  96.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  97.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  98.                    http://www.springframework.org/schema/context
  99.                         http://www.springframework.org/schema/context/spring-context.xsd
  100.                         http://www.springframework.org/schema/aop
  101.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  102.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  103.         <context:component-scan base-package="com.dynamic">
  104.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  105.         </context:component-scan>
  106. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  107.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  108.            xmlns:context="http://www.springframework.org/schema/context"
  109.            xmlns:aop="http://www.springframework.org/schema/aop"
  110.            xmlns:tx="http://www.springframework.org/schema/tx"
  111.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  112.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  113.                    http://www.springframework.org/schema/context
  114.                         http://www.springframework.org/schema/context/spring-context.xsd
  115.                         http://www.springframework.org/schema/aop
  116.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  117.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  118.         <context:component-scan base-package="com.dynamic">
  119.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  120.         </context:component-scan>
  121. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  122.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.            xmlns:context="http://www.springframework.org/schema/context"
  124.            xmlns:aop="http://www.springframework.org/schema/aop"
  125.            xmlns:tx="http://www.springframework.org/schema/tx"
  126.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  127.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  128.                    http://www.springframework.org/schema/context
  129.                         http://www.springframework.org/schema/context/spring-context.xsd
  130.                         http://www.springframework.org/schema/aop
  131.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  132.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  133.         <context:component-scan base-package="com.dynamic">
  134.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  135.         </context:component-scan>
  136. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  137.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  138.            xmlns:context="http://www.springframework.org/schema/context"
  139.            xmlns:aop="http://www.springframework.org/schema/aop"
  140.            xmlns:tx="http://www.springframework.org/schema/tx"
  141.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  142.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  143.                    http://www.springframework.org/schema/context
  144.                         http://www.springframework.org/schema/context/spring-context.xsd
  145.                         http://www.springframework.org/schema/aop
  146.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  147.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  148.         <context:component-scan base-package="com.dynamic">
  149.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  150.         </context:component-scan>
  151. </beans>
复制代码
"""
整合Mybatis框架

把SqlMapConfig.xml配置文件中的内容配置到applicationContext.xml配置文件中,同时配置Spring的声明式事务管理
"""
  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.            xmlns:context="http://www.springframework.org/schema/context"
  4.            xmlns:aop="http://www.springframework.org/schema/aop"
  5.            xmlns:tx="http://www.springframework.org/schema/tx"
  6.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  7.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  8.                    http://www.springframework.org/schema/context
  9.                         http://www.springframework.org/schema/context/spring-context.xsd
  10.                         http://www.springframework.org/schema/aop
  11.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  12.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  13.         <context:component-scan base-package="com.dynamic">
  14.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  15.         </context:component-scan>
  16. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  17.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.            xmlns:context="http://www.springframework.org/schema/context"
  19.            xmlns:aop="http://www.springframework.org/schema/aop"
  20.            xmlns:tx="http://www.springframework.org/schema/tx"
  21.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  22.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  23.                    http://www.springframework.org/schema/context
  24.                         http://www.springframework.org/schema/context/spring-context.xsd
  25.                         http://www.springframework.org/schema/aop
  26.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  27.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  28.         <context:component-scan base-package="com.dynamic">
  29.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  30.         </context:component-scan>
  31. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  32.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33.            xmlns:context="http://www.springframework.org/schema/context"
  34.            xmlns:aop="http://www.springframework.org/schema/aop"
  35.            xmlns:tx="http://www.springframework.org/schema/tx"
  36.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  37.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  38.                    http://www.springframework.org/schema/context
  39.                         http://www.springframework.org/schema/context/spring-context.xsd
  40.                         http://www.springframework.org/schema/aop
  41.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  42.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  43.         <context:component-scan base-package="com.dynamic">
  44.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  45.         </context:component-scan>
  46. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  47.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.            xmlns:context="http://www.springframework.org/schema/context"
  49.            xmlns:aop="http://www.springframework.org/schema/aop"
  50.            xmlns:tx="http://www.springframework.org/schema/tx"
  51.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  52.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  53.                    http://www.springframework.org/schema/context
  54.                         http://www.springframework.org/schema/context/spring-context.xsd
  55.                         http://www.springframework.org/schema/aop
  56.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  57.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  58.         <context:component-scan base-package="com.dynamic">
  59.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  60.         </context:component-scan>
  61. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  62.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63.            xmlns:context="http://www.springframework.org/schema/context"
  64.            xmlns:aop="http://www.springframework.org/schema/aop"
  65.            xmlns:tx="http://www.springframework.org/schema/tx"
  66.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  67.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  68.                    http://www.springframework.org/schema/context
  69.                         http://www.springframework.org/schema/context/spring-context.xsd
  70.                         http://www.springframework.org/schema/aop
  71.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  72.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  73.         <context:component-scan base-package="com.dynamic">
  74.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  75.         </context:component-scan>
  76. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  77.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  78.            xmlns:context="http://www.springframework.org/schema/context"
  79.            xmlns:aop="http://www.springframework.org/schema/aop"
  80.            xmlns:tx="http://www.springframework.org/schema/tx"
  81.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  82.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  83.                    http://www.springframework.org/schema/context
  84.                         http://www.springframework.org/schema/context/spring-context.xsd
  85.                         http://www.springframework.org/schema/aop
  86.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  87.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  88.         <context:component-scan base-package="com.dynamic">
  89.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  90.         </context:component-scan>
  91. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  92.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.            xmlns:context="http://www.springframework.org/schema/context"
  94.            xmlns:aop="http://www.springframework.org/schema/aop"
  95.            xmlns:tx="http://www.springframework.org/schema/tx"
  96.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  97.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  98.                    http://www.springframework.org/schema/context
  99.                         http://www.springframework.org/schema/context/spring-context.xsd
  100.                         http://www.springframework.org/schema/aop
  101.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  102.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  103.         <context:component-scan base-package="com.dynamic">
  104.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  105.         </context:component-scan>
  106. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  107.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  108.            xmlns:context="http://www.springframework.org/schema/context"
  109.            xmlns:aop="http://www.springframework.org/schema/aop"
  110.            xmlns:tx="http://www.springframework.org/schema/tx"
  111.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  112.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  113.                    http://www.springframework.org/schema/context
  114.                         http://www.springframework.org/schema/context/spring-context.xsd
  115.                         http://www.springframework.org/schema/aop
  116.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  117.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  118.         <context:component-scan base-package="com.dynamic">
  119.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  120.         </context:component-scan>
  121. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  122.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.            xmlns:context="http://www.springframework.org/schema/context"
  124.            xmlns:aop="http://www.springframework.org/schema/aop"
  125.            xmlns:tx="http://www.springframework.org/schema/tx"
  126.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  127.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  128.                    http://www.springframework.org/schema/context
  129.                         http://www.springframework.org/schema/context/spring-context.xsd
  130.                         http://www.springframework.org/schema/aop
  131.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  132.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  133.         <context:component-scan base-package="com.dynamic">
  134.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  135.         </context:component-scan>
  136. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  137.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  138.            xmlns:context="http://www.springframework.org/schema/context"
  139.            xmlns:aop="http://www.springframework.org/schema/aop"
  140.            xmlns:tx="http://www.springframework.org/schema/tx"
  141.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  142.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  143.                    http://www.springframework.org/schema/context
  144.                         http://www.springframework.org/schema/context/spring-context.xsd
  145.                         http://www.springframework.org/schema/aop
  146.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  147.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  148.         <context:component-scan base-package="com.dynamic">
  149.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  150.         </context:component-scan>
  151. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  152.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  153.            xmlns:context="http://www.springframework.org/schema/context"
  154.            xmlns:aop="http://www.springframework.org/schema/aop"
  155.            xmlns:tx="http://www.springframework.org/schema/tx"
  156.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  157.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  158.                    http://www.springframework.org/schema/context
  159.                         http://www.springframework.org/schema/context/spring-context.xsd
  160.                         http://www.springframework.org/schema/aop
  161.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  162.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  163.         <context:component-scan base-package="com.dynamic">
  164.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  165.         </context:component-scan>
  166. </beans><beans xmlns="http://www.springframework.org/schema/beans"
  167.            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  168.            xmlns:context="http://www.springframework.org/schema/context"
  169.            xmlns:aop="http://www.springframework.org/schema/aop"
  170.            xmlns:tx="http://www.springframework.org/schema/tx"
  171.            xsi:schemaLocation="http://www.springframework.org/schema/beans
  172.                    http://www.springframework.org/schema/beans/spring-beans.xsd
  173.                    http://www.springframework.org/schema/context
  174.                         http://www.springframework.org/schema/context/spring-context.xsd
  175.                         http://www.springframework.org/schema/aop
  176.                         http://www.springframework.org/schema/aop/spring-aop.xsd
  177.                         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
  178.         <context:component-scan base-package="com.dynamic">
  179.                 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  180.         </context:component-scan>
  181. </beans>                       
复制代码
"""

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

立山

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表