Java开发之ssm三大框架整合(SSM框架整合)

网友投稿 271 2022-07-30


目录1.springmvc2.spring-dao.xml与mybatis-config.xml3.spring-service.xml4.引用

1.springmvc

和只有spring-mvc时一样,web.xml spring-mvc.xml

spring-mvc.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/cache"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context https://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/cache http://springframework.org/schema/cache/spring-cache.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/cache"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context https://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/cache http://springframework.org/schema/cache/spring-cache.xsd">

web.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

paramencoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceResponseEncoding

true

paramencoding

/*

all

/

all

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:Spring-springmvc.xml

hiddenHttpMethodFilter

org.springframework.web.filter.HiddenHttpMethodFilter

hiddenHttpMethodFilter

/*

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

paramencoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

forceResponseEncoding

true

paramencoding

/*

all

/

all

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:Spring-springmvc.xml

hiddenHttpMethodFilter

org.springframework.web.filter.HiddenHttpMethodFilter

hiddenHttpMethodFilter

/*

2.spring-dao.xml与mybatis-config.xml

主要就是spring整合mybatis

spring整合mybatis

在上面的基础上,去掉成接口的实现类了,需要配置dao接口扫描包,我的理解是这个dao接口扫描包中有datasource,有mapper的扫描范围, 它会自动生成这些接口对应的mapper,并将接口的mapper放到xml文件中,所以在spring-service中,直接

引用即可

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/context

https://springframwork.org/schema/context/spring-context.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.org/schema/context

https://springframwork.org/schema/context/spring-context.xsd">

mybatis-config.xml 详细在上面的mybatis整合spring的文章中,它做两件事,配置映射文件路径,配置接口扫描范围,它被import到 spring-dao.xml中。

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

3.spring-service.xml

在这个文件中要进行事务的处理(事务本来就应该是在service层),要将service层的类全部放到ioc容器中,然后这些类中因为调用了dao层的类,然后因为刚才第二部配置了接口扫描包,直接ref获取mapper即可

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.oBhKJqiTrg/schema/context

https://springframwork.org/schema/context/spring-context.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd

http://springframework.oBhKJqiTrg/schema/context

https://springframwork.org/schema/context/spring-context.xsd">

4.引用

将这些文件的引用放到一个大的xml文件中,这个文件只放引用,这样就很容易看

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

http://springframework.org/schema/beans/spring-beans.xsd">

或者在project structure中设置 spring application context,效果是一样的


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot详解如何实现读写分离(springboot读写分离保持数据一致性)
下一篇:Spring整合Mybatis具体代码实现流程(springboot集成mybatis的过程)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~