问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

springmvc 整合 mybitas 的框架 没有在xm...1

发布网友 发布时间:2024-03-03 21:22

我来回答

1个回答

热心网友 时间:2024-04-09 21:01

不说了多了 直接上代码 首先是从程序的入口开始说:
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!--
设置session过期的时间
-->
<session-config>
<session-timeout>20</session-timeout>
</session-config>

<!--
读取spring的配置文件
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring.xml;classpath:config/spring-myBatis.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

<!--
设置字符编码,将所有的字符编码同意设置为utf-8
-->
<filter>
<filter-name>filterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>filterEncoding</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>

<!--
生成一次性验证码的servlet
-->
<servlet>
<servlet-name>verifyCode</servlet-name>
<servlet-class>com.longhang.tool.verifyCode.VerifyCodeServlet</servlet-class>
</servlet>

<!--
将所有*.do的请求交给springMVC的DispatcherServlet来处理
-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/springMVC-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>verifyCode</servlet-name>
<url-pattern>/verifyCode</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

springMVC的配置文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

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

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!--
配置自动扫描的包,让其扫描 com.longhang,controller下面的所有包
-->

<context:component-scan base-package = "com.longhang.controller"></context:component-scan>

<!--
配置视图解析器
将视图逻辑名解析为/*.jsp
-->
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/"></property>
<property name = "suffix" value = ".jsp"></property>
</bean>
</beans>

spring.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<context:property-placeholder location="classpath:config/druid.properties" />
<!-- 自动扫描(自动注入) -->
<context:component-scan base-package = "com.longhang.service"></context:component-scan>

</beans>

spring-myBatis.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
<!-- 配置数据源 --><!--
<bean name = "datasource" class = "com.alibaba.druid.pool.DruidDataSource" init-method = "init" destroy-method = "close">
<property name ="url" value = "${jdbc_url}"></property>
<property name="username" value="${jdbc_userName}" />
<property name="password" value="${jdbc_password}" />
</bean>

--><bean name = "datasource" class = "com.alibaba.druid.pool.DruidDataSource" init-method = "init" destroy-method = "close">
<property name ="url" value = "jdbc:mysql://localhost:8000/bookShopping"></property>
<property name="username" value="root" />
<property name="password" value="13072399672" />
</bean>

<!--配置sqlSessionFactory 并读取mybatis的一些配置-->
<bean name = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean">
<property name = "dataSource" ref = "datasource"></property>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>

<!--
自动扫描 将Mapper接口生成代理注入到Spring
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.longhang.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

<!--
配置事物
-->
<bean id = "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name = "dataSource" ref = "datasource"></property>
</bean>

<!--
<tx:annotation-driven transaction-manager = "transactionManager"/>
-->

<!--
事物的具体内容
-->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="append*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="repair" propagation="REQUIRED" />
<tx:method name="delAndRepair" propagation="REQUIRED" />

<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="load*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="datagrid*" propagation="SUPPORTS" />

<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>

<!--
定义一个切面,在定义的切面上加入事物
-->
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.longhang.service..*Impl.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>

</beans>
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
父母离异的话,会不会导致孩子心智不成熟? 过节 公司给我们发的购物卡 这个怎么做分录 属于福利费吗 需要计提吗... 乡村振兴公务员和省考公务员有什么区别 ...小时候跟着爷爷学国画书法,小受家是农村的,小受姓夏或叶,他带着他... 瑞麒X1安全装置 瑞麒X1的舒适型和豪华型有什么区别?配置有哪些不同的地方?这5000块多在... 瑞麒X1的安全性能方面配置如何? 脚崴了 有大量於血 怎么样才能快速消肿 脚崴了外侧出现瘀血浮肿怎么消除? ...换了我喜欢的发型,但是穿了件有点透明的衣服,可以看到肩_百度... spring mvc 框架操作什么能够自动生成dao包实体类... java 请问下SpringMVC中怎么把数据库的数据映射成...1 j2ee、实体类必须要和数据库里的字段一模一样吗? 陶行知作文大赛 用铸铁锅炖汤会变色吗? 舌头边有齿痕怎么办235 ★★怎么办?舌头有齿痕!!!应该怎么办!舌头上有裂痕是怎么回...8 舌头中间有齿痕!!!!我该怎么办!! 舌头上有齿痕怎么办9 一阵风过后,天空中变得干净明亮。 一阵风吹过() 周围好像明亮了许多? 一阵风过后,周围一下子亮起来? 一阵风吹过什么周围一下子明亮起来? 我还算白不长痘痘,就是有一点粉刺和黑头,还有点斑斑哦,想要一款可以遮 ... JAVA和数据库问题。新建databaseWeb项目,把my...6 穿汉服去苏州的园林和同里会不会被阻拦或多收些什么费用? Mysql 数据库文件存储在哪个目录132 舌苔厚白有齿痕口臭是怎么回事 舌苔白湿气重有口臭怎么调理。2 qq炫舞浪漫之心怎么和伴侣一起乘坐 梦见妈妈我哭了7 妈妈我哭了 歌词1 我想注册个新,怎么注册?328 怎么注册420 怎么申请新的?453 怎么注册个新?269 怎样注册428 怎样申请并注册467 潍坊怎么买水货thinkpad t400 想买台水货Thinkpad T400,有要注意的么?? 武汉ibm水货 我想申请一个怎么申请的333 怎样用手机申请887 怎么申请新的?453 怎样申请并注册467 新手机号码怎样申请558 怎么注册420 怎样申请新的631 写流行歌曲需要用什么? 我想申请一个怎么申请的333