最近写了个项目,自己第一次搭建架构,费了好久才搭成功,记录下来,为以后留个参考。
前台使用的是jquery
web.xml
2 <context-param>
3 <param-name>contextConfigLocation</param-name>
4 <param-value>
5 classpath*:applicationContext-common.xml,
6 classpath*:applicationContext-dao.xml,
7 classpath*:applicationContext-service.xml,
8 classpath*:applicationContext-action.xml
9 </param-value>
10 </context-param>
11
12 <welcome-file-list>
13 <welcome-file>login.jsp</welcome-file>
14 </welcome-file-list>
15 <filter>
16 <filter-name>struts2</filter-name>
17 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
18 </filter>
19
20 <filter-mapping>
21 <filter-name>struts2</filter-name>
22 <url-pattern>/*</url-pattern>
23 </filter-mapping>
24 <listener>
25 <listener-class>
26 org.springframework.web.context.ContextLoaderListener
27 </listener-class>
28 </listener>
29 <session-config>
30 <session-timeout>20</session-timeout>
31 </session-config>
32 <filter>
33 <filter-name>struts-cleanup</filter-name>
34 <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
35 </filter>
36 <filter-mapping>
37 <filter-name>struts-cleanup</filter-name>
38 <url-pattern>/*</url-pattern>
39 </filter-mapping>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/com" extends="struts-default">
<action name="login" class="loginAction" method="login">
<result name="success">/main.jsp</result>
<result name="error">/loginError.jsp</result>
<result name="fail">/error.jsp</result>
</action>
<action name="logoff" class="logoffAction" method="logoff">
<result name="success" type="redirect">/login.jsp</result>
</action>
</package>
</struts>
applicationContext-xxx.xml下面这四个其实可以放在一个配置档里,区分下来只是为了便于查找清晰点applicationContext-action.xml
1 <bean id="loginAction" class="com.ivo.action.LoginAction" scope="prototype">
2 <property name="checkAuthorityService" ref="checkAuthorityService" />
3 </bean>
applicationContext-service.xml
1 <bean id="checkAuthorityService" class="com.ivo.service.impl.CheckAuthorityService">
2 <property name="uasUserDao" ref="uasUserDao" />
3 </bean>
applicationContext-dao.xml
1 <bean id="uasUserDao" class="com.ivo.dao.impl.UasUserDao">
2 <property name="sqlMapClient" ref="sqlMapClient" />
3 </bean>
applicationCtontext-common.xml
1 <bean id="mySqlDataSource"
2 class="org.springframework.jdbc.datasource.DriverManagerDataSource">
3 <property name="driverClassName">
4 <value>com.mysql.jdbc.Driver</value>
5 </property>
6 <property name="url">
7 <value>
8 jdbc:mysql://10.20.53.106:3306/qrademo
9 </value>
10 </property>
11 <property name="username">
12 <value>root</value>
13 </property>
14 <property name="password">
15 <value>Ivo123</value>
16 </property>
17 </bean>
18 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
19 <property name="configLocation">
20 <value>classpath:ibatis-config.xml</value>
21 </property>
22 <property name="dataSource">
23 <ref local="mySqlDataSource" />
24 </property>
25 </bean>
ibatis-config.xml
1 <sqlMapConfig>
2 <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true"
3 maxRequests="300" maxSessions="200" maxTransactions="100" useStatementNamespaces="true" />
4 <sqlMap resource="com/ivo/pojo/xml/UasUser.xml" />
5 </sqlMapConfig>
差不多建这些,当然还有许多jar包需要导