spring+struts+mybatis三大框架整合配置

本文提供了一个Spring、Struts和Mybatis三大框架整合的小型Demo,详细介绍了从创建web项目、配置目录结构,到添加各框架、配置文件、编写DAO、Service、Action类以及Struts.xml和jsp的全过程。
摘要由CSDN通过智能技术生成

很多使用中都会用到spring+Struts+mybatis这三大框架整合的项目,下面就是这三大框架的一个小dome。可供参考


*,先看下整体目录结构及架包



一,首先创建web项目并建立目录结构,添加Struts,spring框架,并行进配置
1.1添加Struts,spring框架此处省略详细步骤,百度一下都能得到很多,添加成功后会看到如下图所示有Struts及spring的XML配置文件

建立目录结构时最好就建立好实体类



1.2框架添加进来后就是进行配置了
首先配置web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <!-- struts2启动配置 -->
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>
  		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  	</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>*.action</url-pattern>
  </filter-mapping>
  <!-- spring启动配置 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>Classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  </web-app>
1.3,配置好web.xml后添加jdbc外部链接文件,(也可以直接在mybatis的XML文件中直接配置)
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///test?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
jdbc.maxActive =2
jdbc.maxIdle =5
jdbc.minIdle=1
jdbc.initialSize =3
jdbc.maxWait =3000
1.4,配置spring的XML文件,applicationContext.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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-3.1.x
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值