Spring stust2 mybati
来源:互联网 发布:python 定时 编辑:程序博客网 时间:2024/05/07 20:06
1.首先导入相应的架包,以下为pom.xml配置文件实例说明,需要的架包;
2.以下是web.xml配置的相关文件2.1首先是Sturst2的配置
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 自从Struts 2.1.3以后,下面的FilterDispatcher已经标注为过时
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> --> </filter><filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
***Struts2前端请求,Struts进行相关拦截,然后找struts.xml,找到Action进行处理 Spring负责Bean的管理,
也需要一个配置文件以applicationContext.xml为例 下面这段代码就可以把两者连接起来,需要一个Spring-struts2-plugin插件上面有具体的架包
。。<!-- applicationContext.xml --> <!-- Spring监听器 会自动查找WEB-INF下的applicationContext.xml文件 --> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
2.2 以下为applicationContext.xml文件
配置自动扫描器
<context:component-scan base-package="com"></context:component-scan>
//springAop切面的代理机制 <!-- 自动代理类 -->
<aop:aspectj-autoproxy ></aop:aspectj-autoproxy>
**//为数据的相关操作,只有配置过程和相应的架包**
<!-- 注册jdbc.properties方法 1 :bean方式注册
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"></property>
</bean>
-->
<!-- 注册jdbc.properties方法 2种:context方式注册-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据源配置:可以C3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> -->
<!--
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源的获取 --> <property name="dataSource" ref="dataSource"></property>
<!-- 得到mybatis的核心配置文件
<property name="configLocation" value="classpath:mybatis.xml"/>
--> <!-- 自动扫描mapping.xml文件,**表示迭代查找 代替了 config -->
<property name="mapperLocations" value="classpath:com/bean/**/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
</beans>
2.3以下为struts.xml配置文件<struts> <!-- 改变Struts2默认请求action -->
<constant name="struts.action.extension" value="action,do1,"></constant>
<!-- 设置当struts.xml文件改动时,是否重新加载 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
//文件上传利用了struts的拦截器功能
<package name="upload" extends="struts-default" namespace="/upload">
//ajax的相关请求
</package>
//关于和json的连接需要两个架包,上面有具体的
<package name="ajax" extends="json-default" namespace="/ajax">
<action name="ajaxlogin" class="com.web.Ajaxlogin" method="Axajlogin1">
<result type="json"></result>
</action>
</package>
</struts>
关于项目的结构是按照mvc严格分层的 具体的不多说,不足之处,望见谅,有什么好的想法,也可以留言;
2.以下是web.xml配置的相关文件2.1首先是Sturst2的配置
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 自从Struts 2.1.3以后,下面的FilterDispatcher已经标注为过时
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> --> </filter><filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
***Struts2前端请求,Struts进行相关拦截,然后找struts.xml,找到Action进行处理 Spring负责Bean的管理,
也需要一个配置文件以applicationContext.xml为例 下面这段代码就可以把两者连接起来,需要一个Spring-struts2-plugin插件上面有具体的架包
。。<!-- applicationContext.xml --> <!-- Spring监听器 会自动查找WEB-INF下的applicationContext.xml文件 --> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
2.2 以下为applicationContext.xml文件
配置自动扫描器
<context:component-scan base-package="com"></context:component-scan>
//springAop切面的代理机制 <!-- 自动代理类 -->
<aop:aspectj-autoproxy ></aop:aspectj-autoproxy>
**//为数据的相关操作,只有配置过程和相应的架包**
<!-- 注册jdbc.properties方法 1 :bean方式注册
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"></property>
</bean>
-->
<!-- 注册jdbc.properties方法 2种:context方式注册-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据源配置:可以C3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<!--2 JDBC模版注入 C3p0要用的模板<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> -->
<!--
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源的获取 --> <property name="dataSource" ref="dataSource"></property>
<!-- 得到mybatis的核心配置文件
<property name="configLocation" value="classpath:mybatis.xml"/>
--> <!-- 自动扫描mapping.xml文件,**表示迭代查找 代替了 config -->
<property name="mapperLocations" value="classpath:com/bean/**/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
</beans>
2.3以下为struts.xml配置文件<struts> <!-- 改变Struts2默认请求action -->
<constant name="struts.action.extension" value="action,do1,"></constant>
<!-- 设置当struts.xml文件改动时,是否重新加载 -->
<constant name="struts.configuration.xml.reload" value="true"></constant>
//文件上传利用了struts的拦截器功能
<package name="upload" extends="struts-default" namespace="/upload">
<action name="upload" class="com.web.UploadAction1" method="upload1">
<result>/pages/upload/upload.jsp</result>
</action>//ajax的相关请求
</package>
//关于和json的连接需要两个架包,上面有具体的
<package name="ajax" extends="json-default" namespace="/ajax">
<action name="ajaxlogin" class="com.web.Ajaxlogin" method="Axajlogin1">
<result type="json"></result>
</action>
</package>
</struts>
关于项目的结构是按照mvc严格分层的 具体的不多说,不足之处,望见谅,有什么好的想法,也可以留言;
0 0
- Spring stust2 mybati
- spring+SpringMVC+mybati整合JBPM
- SpringMVC+Spring+Mybati+Maven+Mysql整合
- Stust2配置
- Spring Boot mybati-plus .yml文件的配置文件
- 使用idea maven实现Spring+mybati的整合
- 使用idea maven实现Spring+mybati的整合
- mybati学习(三)
- MyBati调用存储过程
- mybati源码之ReuseExecutor
- mybati缓存机制
- mybati事物配置
- 经典Mybati面试题
- mybati paginator分页问题
- mybati 批量操作的几种方式
- 初学MyBati和使用Mybatis-Generator
- mybati(ibatis)中的动态sql <dynamic prepend="where">的详解
- 手把手教你如何通过general自动创建mybati中mapper映射接口以及bean
- Window内存管理方式:段存储、页存储、段页存储
- View绘制流程
- IntelliJ Idea 常用快捷键 列表(实战终极总结!!!!)
- string类常见函数汇总(一)
- 怎么卸载影子系统?卸载影子系统解决方法
- Spring stust2 mybati
- 欢迎使用CSDN-markdown编辑器
- kibana介绍
- Tomcat 6 JNDI数据源详解
- iOS 中 Auto Layout(自动布局)
- 七层登录续篇
- TCP拥塞管理
- 入坑 Chromebook
- 菜鸟漫漫路