当前位置:编程学习 > JS >>

struts2+spring+ibatis框架搭建参考

我到公司 搞的第一个项目的用的框架用的就是这个,所以我已经自己试着自己搭建,其实跟三大框架搭建也差不多

 

 

\
这是我们公司的包结构,包结构不用多说,大家都看的懂,jdbc.properties这个配置文件是在spring里面要用的访问数据库的配置

log4j是一个日志的配置文件,说明错误的一些还有访问的一些信息写入到哪里

sqlMapConfig配置文件是ibatis的总配置文件,\下面写的就是有哪些mapping配置文件,放置的位置就在和entities包下,每一个包写一个配置一个

如果,要涉及要多表查询,就要再创建一个类就好,把2张表中用到的属性,插入到这个类里面

spring-config这个文件夹下放的就是spring的几个配置文件

一个写的就是action的创建,一个是biz层的创建,还有就是DAO

其实struts的action可以用spring来创建,用的就是加了一句话

 


    <constant name="struts.objectFactory" value="spring" />

 


这些包结构配置后之后就是配置web.xml

就是告诉tomcat哪些是struts配置文件,哪些是spring配置文件,让tomcat启动的时候,就可以创建了

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>HD_U</display-name>
  <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>HD_U.root</param-value>
  </context-param>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>//添加日志类的监听
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>//spring的监听类
  </listener>
  <context-param>
    <param-name>log4jConfigLocation</param-name>//日志类监听的初始化的参数,告诉配置文件在哪里
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <filter>
    <filter-name>struts2</filter-name>//struts2的单控制器
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>//spring的监听类告诉spring配置文件在哪里
    <param-value>classpath*:/spring-config/applicationContext*.xml</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>InitServlet</display-name>
    <servlet-name>InitServlet</servlet-name>
    <servlet-class>com.hdu.web.common.InitServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
</web-app>

 

 

 


 

补充:Web开发 , Jsp ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,