一 . 分工:
Struts2 :
负责流程控制,主要JSP页面发送请求,经过web.xml的StrutsPrepareAndExecuteFilter(struts核心控制器)到struts.xml找匹配的name,到对应的action里面找到相匹配的方法,返回struts.xml,返回对应的jsp
jsp页面的form请求:
—>
web.xml的struts核心控制器:
—>
struts.xml:
—>
action里面的方法:
—>
struts里面的name:
—>
返回对应的jsp页面并循环出数据:
Spring:
负责各个类,对象的创建,包括action,service,dao,数据连接对象,Ibatis框架的核心对象sqlMapClient,Spring自身的事务处理扩展对象transactionManager。
Ibatis:
负责对JDBC的封装,简化访问数据的程序。
二 . 环境的搭建:
1 . 需要考入的jar包:
commons-fileupload-1.2.1.jar(Struts2:文件上传)
commons-io-1.3.2.jar(Struts2:文件上传)
freemarker-2.3.15.jar(Struts2:视图展现技术)
ognl-2.7.3.jar(Struts2:对象图形导航语言,用于做数据操作)
struts2-core-2.1.8.1.jar(Struts2:核心jar包)
xwork-core-2.1.6.jar(Struts2:webwork框架的核心jar包)
commons-logging.jar(Spring:日志输出操作,实现日志输出的转换)
junit-3.8.2.jar(非必须:单元测试jar包)
log4j-1.2.15.jar(非必须:日志输出jar包)
spring.jar(Spring:核心jar包)
struts2-spring-plugin-2.1.8.1.jar(Struts2和Spring的合并jar包)
c3p0-0.9.1.2.jar(做数据源操作的jar包)
ibatis-2.3.4.726.jar(Ibatis:核心jar包)
ojdbc14.jar(oracle数据库的连接jar包)
aspectjrt.jar(Spring:支持AOP功能的jar包)
aspectjweaver.jar(Spring:支持AOP功能的jar包)
cglib-nodep-2.1_3.jar(Spring:实现基于继承的动态代理)
2 . 配置文件:
三 . 各个配置文件的编写:
.
jsp页面:
.
<%@page contentType="text/html; charset=utf-8"%>
<%@page session="false"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="<%=path %>/web/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path %>/web/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".tiptop a").click(function() {
$(".tip").fadeOut(200);
});
$(".sure").click(function() {
$(".tip").fadeOut(100);
});
$(".cancel").click(function() {
$(".tip").fadeOut(100);
});
});
function nextpage(pageNum) {
$("#pageNum").val(pageNum + 1);
document.getElementById("pagerForm").submit();
}
function beforepage(pageNum) {
$("#pageNum").val(pageNum - 1);
document.getElementById("pagerForm").submit();
}
function ifDelete(id){
if(confirm("确定删除么?")){
window.location.href = "<%=path%>/campusLife!delete.do?campusLife.id="+id;
}
}
function ifUpdate(year){
if(confirm("确定修改么?")){
window.location.href = "<%=path%>/campusLife!firstUpdate.do?campusLife.year="+year;
}
}
</script>
</head>
<body>
<div class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="#">首页</a></li>
<li><a href="#">学生发展</a></li>
<li><a href="#">校园生活</a></li>
</ul>
</div>
<form id="pagerForm" action="<%=path%>/campusLife!noviceTeacherList.do" method="post">
<div class="rightinfo">
<div class="tools">
<ul class="toolbar">
<li class="click"><a href="<%=path %>/web/zxk/campusLifeMod.jsp"><span><img src="<%=path %>/web/images/t01.png" /></span>添加</a></li>
</ul>
<ul class="toolbar1">
<li><span><img src="<%=path %>/web/images/t05.png" /></span>设置</li>
</ul>
</div>
<table class="tablelist">
<thead>
<tr>
<th>学生社团数量<i class="sort"><img src="<%=path %>/web/images/px.gif" /></i></th>
<th>未参与社团学生数</th>
<th>操场面积</th>
<th>体育场馆面积</th>
<th>食堂面积</th>
<th>年限</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<s:iterator value="campusLifeList" var="nt" status="st">
<tr>
<td>${nt.pupCombo}</td>
<td>${nt.noJoin}</td>
<td>${nt.maidanSpace}</td>
<td>${nt.stadiaSpace}</td>
<td>${nt.messSpace}</td>
<td>${nt.year}</td>
<td>
<a href="#" onclick="ifUpdate(${nt.year})" class="tablelink">修改</a>
<a href="#" onclick="ifDelete(${nt.id})" class="tablelink"> 删除</a>
</td>
</tr>
</s:iterator>
</tbody>
</table>
<div class="pagin">
<div class="message">共<i class="blue">${totalCount} </i>条记录,共 ${pageCount} 页 , 当前显示第 <i class="blue">${pageNum } </i>页</div>
<ul class="paginList">
<li class="paginItem"><a href="javascript:;" onclick="beforepage(${pageNum});"><span class="pagepre"></span></a></li>
<li class="paginItem"><a href="javascript:;" onclick="nextpage(${pageNum});"><span class="pagenxt"></span></a></li>
</ul>
</div>
</div>
</form>
<div class="tip">
<div class="tiptop"><span>提示信息</span><a></a></div>
<div class="tipinfo">
<span><img src="images/ticon.png" /></span>
<div class="tipright">
<p>是否确认对信息的修改 ?</p>
<cite>如果是请点击确定按钮 ,否则请点取消。</cite>
</div>
</div>
<div class="tipbtn">
<input name="" type="button" class="sure" value="确定" />
<input name="" type="button" class="cancel" value="取消" />
</div>
</div>
<script type="text/javascript">
$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
.
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">
<context-param>
<param-name>dwz</param-name>
<param-value>lottery.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<!--Spring ApplicationContext 载入 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>com.dwz.web.action.Timergettock</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>WxInfo</servlet-name>
<servlet-class>com.dwz.web.action.WxInfo</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Timergettock</servlet-name>
<servlet-class>com.dwz.web.action.Timergettock</servlet-class>
</servlet>
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>
.
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="admin" extends="struts-default" namespace="/">
<action name="employmentStatus" class="com.dwz.web.action.EmploymentStatusAction">
<result name="employmentStatusList">web/zxk/campusLife.jsp</result>
<result name="statusList">web/zxk/campusLifeModU.jsp</result>
</action>
</package>
</struts>
.
action:
.
package com.dwz.web.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.dwz.entity.EmploymentStatus;
import com.dwz.service.EmploymentStatusService;
/**
* @className: EmploymentStatusAction
* @description: 就业情况action
* @author:zxk
* @date: 2017-11-23 13:18
*/
@SuppressWarnings("serial")
public class EmploymentStatusAction extends BaseAction{
@SuppressWarnings("unchecked")
public HashMap map = new HashMap();
public EmploymentStatusService employmentStatusService;
public List<EmploymentStatus> employmentStatusList;
public EmploymentStatus employmentStatus;
public List<EmploymentStatus> statusList;
public Integer pageNum=1;
public Integer currentPage = 1; // 当前是第几页
public String targetType="navTab"; // navTab或dialog,用来标记是navTab上的分页还是dialog上的分页
public Integer totalCount=0; // 总条数
public Integer numPerPage=10; // 每页显示多少条
public Integer pageNumShown=10; // 页标数字多少个
public Integer pageCount = 0; // 总页数
public Integer page;
public Integer rows;
public Integer getPage() {
return page;
}
public Integer getRows() {
return rows;
}
public void setPage(Integer page) {
this.page = page;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPageNum() {
return pageNum;
}
public Integer getCurrentPage() {
return currentPage;
}
public String getTargetType() {
return targetType;
}
public Integer getTotalCount() {
return totalCount;
}
public Integer getNumPerPage() {
return numPerPage;
}
public Integer getPageNumShown() {
return pageNumShown;
}
public Integer getPageCount() {
return pageCount;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public void setTargetType(String targetType) {
this.targetType = targetType;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
public void setNumPerPage(Integer numPerPage) {
this.numPerPage = numPerPage;
}
public void setPageNumShown(Integer pageNumShown) {
this.pageNumShown = pageNumShown;
}
public void setPageCount(Integer pageCount) {
this.pageCount = pageCount;
}
public HashMap getMap() {
return map;
}
public void setMap(HashMap map) {
this.map = map;
}
public EmploymentStatusService getEmploymentStatusService() {
return employmentStatusService;
}
public void setEmploymentStatusService(
EmploymentStatusService employmentStatusService) {
this.employmentStatusService = employmentStatusService;
}
public List<EmploymentStatus> getEmploymentStatusList() {
return employmentStatusList;
}
public void setEmploymentStatusList(List<EmploymentStatus> employmentStatusList) {
this.employmentStatusList = employmentStatusList;
}
public EmploymentStatus getEmploymentStatus() {
return employmentStatus;
}
public void setEmploymentStatus(EmploymentStatus employmentStatus) {
this.employmentStatus = employmentStatus;
}
public List<EmploymentStatus> getStatusList() {
return statusList;
}
public void setStatusList(List<EmploymentStatus> statusList) {
this.statusList = statusList;
}
@SuppressWarnings("unchecked")
public void page(){
map = new HashMap();
totalCount = employmentStatusService.findCount();
if (totalCount != null) {
pageCount = totalCount % numPerPage == 0 ? totalCount / numPerPage : totalCount / numPerPage + 1;
}
}
/**
* @className: EmploymentStatusAction
* @desicription: 分页查询新任所有就业情况
* @author: zxk
* @date: 2017-11-23 13:18
*/
public String noviceTeacherList(){
page();
map = new HashMap();
page = pageNum * numPerPage - numPerPage;
if (page < 0){
page = 0;
}
rows = numPerPage;
map.put("page",page);
map.put("rows", rows);
String limitPage = "limit" + page + "," + rows;
System.out.println("limitPage = " + limitPage);
employmentStatusList = employmentStatusService.findList(map);
return "employmentStatusList";
}
/**
* @className: EmploymentStatusAction
* @desicription: 根据年份添加就业情况,有则添加,无则修改
* @author: zxk
* @date: 2017-11-23 13:18
*/
@SuppressWarnings("unchecked")
public String insert(){
map = new HashMap();
map.put("year", employmentStatus.getYear());
//得到这个年份的数据
EmploymentStatus teacher = employmentStatusService.findTeacherCultivateByYear(map);
map.put("contra", employmentStatus.getContra());
map.put("one", employmentStatus.getOne());
map.put("juche", employmentStatus.getJuche());
//根据年份判断是否存在
if (teacher != null) {
//这一年已经录入,则修改
map.put("id", teacher.getId());
employmentStatusService.update(map);
}else{
//这一年未录入,则添加
employmentStatusService.insert(map);
}
return noviceTeacherList();
}
/**
* @className: EmploymentStatusAction
* @desicription: 根据年份修改就业情况,先得到要修改的这个对象
* @author: zxl
* @date: 2017-11-23 13:18
*/
public String firstUpdate(){
map = new HashMap();
map.put("year", employmentStatus.getYear());
statusList = new ArrayList<EmploymentStatus>();
employmentStatus = employmentStatusService.findTeacherCultivateByYear(map);
//先判断非空
if (employmentStatus != null) {
statusList.add(employmentStatus);
}
return "statusList";
}
/**
* @className: EmploymentStatusAction
* @desicription: 根据id修改根据年份查出的对象
* @author: zxk
* @date: 2017-11-23 13:18
*/
@SuppressWarnings("unchecked")
public String update(){
map = new HashMap();
map.put("id", employmentStatus.getId());
map.put("contra", employmentStatus.getContra());
map.put("one", employmentStatus.getOne());
map.put("juche", employmentStatus.getJuche());
map.put("year", employmentStatus.getYear());
employmentStatusService.update(map);
return noviceTeacherList();
}
/**
* @className: EmploymentStatusAction
* @desicription: 根据id删除就业情况,也就是修改delete为0
* @author: zxk
* @date: 2017-11-23 13:18
*/
@SuppressWarnings("unchecked")
public String delete(){
map = new HashMap();
map.put("id", employmentStatus.getId());
EmploymentStatus teacher = employmentStatusService.findTeacherCultivateById(map);
if (teacher != null) {
employmentStatusService.deleted(map);
}
return noviceTeacherList();
}
}
.
xml
.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="employmentStatus">
<select id="findListEmploymentStatus" parameterClass="HashMap" resultClass="com.dwz.entity.EmploymentStatus" >
<![CDATA[
SELECT
id,contra,one,juche,year
FROM
employment_status WHERE 1=1 AND deleted = 1
]]>
LIMIT #page#,#rows#
</select>
<select id="findCountEmploymentStatus" resultClass="com.dwz.entity.EmploymentStatus" >
<![CDATA[
SELECT * FROM employment_status WHERE 1=1 AND deleted = 1
]]>
</select>
<select id="findNoviceTeacherByYearEmploymentStatus" parameterClass="HashMap" resultClass="com.dwz.entity.EmploymentStatus" >
<![CDATA[
SELECT
id,contra,one,juche,year
FROM
employment_status where 1=1 AND deleted = 1
]]>
<isNotEmpty property="year">
AND year = #year#
</isNotEmpty>
</select>
<select id="findNoviceTeacherByIdEmploymentStatus" parameterClass="HashMap" resultClass="com.dwz.entity.EmploymentStatus" >
<![CDATA[
SELECT
id,contra,one,juche,year
FROM
employment_status where 1=1 AND deleted = 1
]]>
<isNotEmpty property="id">
AND id = #id#
</isNotEmpty>
</select>
<insert id="insertEmploymentStatus" parameterClass="HashMap" >
<![CDATA[
INSERT employment_status
(
contra,one,juche,year
)
VALUES(
#contra#,#one#,#juche#,#year#
)
]]>
</insert>
<update id="updateEmploymentStatus" parameterClass="HashMap" >
<![CDATA[
UPDATE
employment_status
SET
contra = #contra#,one = #one#,juche = #juche#,year = #year#
WHERE id = #id#
]]>
</update>
<update id="deletedEmploymentStatus" parameterClass="HashMap" >
<![CDATA[
UPDATE
employment_status
SET
deleted = 0
WHERE
id = #id#
]]>
</update>
</sqlMap>
.
dao
.
package com.dwz.daos;
import java.util.HashMap;
import java.util.List;
import com.dwz.entity.EmploymentStatus;
public interface EmploymentStatusDao {
@SuppressWarnings("unchecked")
public List<EmploymentStatus> findList(HashMap map);
public List<EmploymentStatus> findCount();
@SuppressWarnings("unchecked")
public EmploymentStatus findNoviceTeacherByYear(HashMap map);
@SuppressWarnings("unchecked")
public EmploymentStatus findNoviceTeacherById(HashMap map);
@SuppressWarnings("unchecked")
public void insert(HashMap map);
@SuppressWarnings("unchecked")
public void update(HashMap map);
@SuppressWarnings("unchecked")
public void deleted(HashMap map);
}
.
daoimpl
.
package com.dwz.daos;
import java.util.HashMap;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.dwz.entity.EmploymentStatus;
public class EmploymentStatusDaoImpl extends SqlMapClientDaoSupport implements EmploymentStatusDao{
@SuppressWarnings("unchecked")
@Override
public List<EmploymentStatus> findList(HashMap map) {
return getSqlMapClientTemplate().queryForList("findListEmploymentStatus", map);
}
public List<EmploymentStatus> findCount() {
return getSqlMapClientTemplate().queryForList("findCountEmploymentStatus");
}
@SuppressWarnings("unchecked")
@Override
public EmploymentStatus findNoviceTeacherByYear(HashMap map) {
return (EmploymentStatus) getSqlMapClientTemplate().queryForObject("findNoviceTeacherByYearEmploymentStatus",map);
}
@SuppressWarnings("unchecked")
@Override
public EmploymentStatus findNoviceTeacherById(HashMap map) {
return (EmploymentStatus) getSqlMapClientTemplate().queryForObject("findNoviceTeacherByIdEmploymentStatus",map);
}
@SuppressWarnings("unchecked")
@Override
public void insert(HashMap map) {
getSqlMapClientTemplate().insert("insertEmploymentStatus", map);
}
@SuppressWarnings("unchecked")
@Override
public void update(HashMap map) {
getSqlMapClientTemplate().update("updateEmploymentStatus", map);
}
@SuppressWarnings("unchecked")
@Override
public void deleted(HashMap map) {
getSqlMapClientTemplate().update("deletedEmploymentStatus", map);
}
}
.
service
.
package com.dwz.service;
import java.util.HashMap;
import java.util.List;
import com.dwz.entity.EmploymentStatus;
/**
* @className: EmploymentStatusService
* @description: 就业情况service
* @author:zxk
* @date: 2017-11-23 13:15
*/
public interface EmploymentStatusService {
/**
* @className: EmploymentStatusService
* @description: 分页查询所有就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public List<EmploymentStatus> findList(HashMap map);
/**
* @className: EmploymentStatusService
* @description: 查询所有就业情况个数
* @author:zxk
* @date: 2017-11-23 13:15
*/
public Integer findCount();
/**
* @className: EmploymentStatusService
* @description: 通过年份查询单个就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public EmploymentStatus findTeacherCultivateByYear(HashMap map);
/**
* @className: EmploymentStatusService
* @description: 通过id查询单个就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public EmploymentStatus findTeacherCultivateById(HashMap map);
/**
* @className: EmploymentStatusService
* @description: 添加单个就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public void insert(HashMap map);
/**
* @className: EmploymentStatusService
* @description: 修改单个就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public void update(HashMap map);
/**
* @className: EmploymentStatusService
* @description: 删除单个就业情况
* @author:zxk
* @date: 2017-11-23 13:15
*/
@SuppressWarnings("unchecked")
public void deleted(HashMap map);
}
.
serviceImpl
.
package com.dwz.service;
import java.util.HashMap;
import java.util.List;
import com.dwz.daos.EmploymentStatusDao;
import com.dwz.entity.EmploymentStatus;
public class EmploymentStatusServiceImpl implements EmploymentStatusService{
private EmploymentStatusDao employmentStatusDao;
public EmploymentStatusDao getEmploymentStatusDao() {
return employmentStatusDao;
}
public void setEmploymentStatusDao(EmploymentStatusDao employmentStatusDao) {
this.employmentStatusDao = employmentStatusDao;
}
@Override
public Integer findCount() {
Integer sum = null;
if (employmentStatusDao.findCount() != null) {
sum = employmentStatusDao.findCount().size();
}
return sum;
}
@Override
public List<EmploymentStatus> findList(HashMap map) {
return employmentStatusDao.findList(map);
}
@Override
public EmploymentStatus findTeacherCultivateById(HashMap map) {
return employmentStatusDao.findNoviceTeacherById(map);
}
@Override
public EmploymentStatus findTeacherCultivateByYear(HashMap map) {
return employmentStatusDao.findNoviceTeacherByYear(map);
}
@SuppressWarnings("unchecked")
@Override
public void insert(HashMap map) {
employmentStatusDao.insert(map);
}
@SuppressWarnings("unchecked")
@Override
public void update(HashMap map) {
employmentStatusDao.update(map);
}
@SuppressWarnings("unchecked")
@Override
public void deleted(HashMap map) {
employmentStatusDao.deleted(map);
}
}
.
applicationContext-dwz.xml
.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!--2017-11-23 13:28 zxk 就业情况 start-->
<!-- dao层类的设置 ,关联sqlMapClient ,sqlMapClient关联config.xml-->
<bean id="employmentStatusDao" class="com.dwz.daos.EmploymentStatusDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
<!-- service层类的设置,关联dao -->
<bean id="employmentStatusService" class="com.dwz.service.EmploymentStatusServiceImpl">
<property name="employmentStatusDao" ref="employmentStatusDao"></property>
</bean>
<!-- action层类的设置,关联service -->
<bean id="employmentStatusAction" class="com.dwz.web.action.EmploymentStatusAction">
<property name="employmentStatusService" ref="employmentStatusService"></property>
</bean>
<!--2017-11-23 13:28 zxk 就业情况 end-->
</beans>
.
applicationContext.xml
.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!--<property name="jdbcUrl" value="jdbc:oracle:thin:@10.131.20.226:1521:orcl"/>
--><beans>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<!-- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/gaoyh"/> 121.40.186.233 10.0.3.244-->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/scrm?useUnicode=true&characterEncoding=utf-8&useOldAliasMetadataBehavior=true"/>
<property name="user" value="root"/>
<property name="password" value="qzt"/> <!-- atdev2015P AndyChen-->
<property name="minPoolSize"><value>1</value></property>
<property name="maxPoolSize"><value>50</value></property>
<property name="maxIdleTime"><value>25000</value></property>
<property name="acquireIncrement"><value>1</value></property>
<property name="maxStatements"><value>0</value></property>
<property name="initialPoolSize"><value>2</value></property>
<property name="idleConnectionTestPeriod"><value>18000</value></property>
<property name="acquireRetryAttempts"><value>30</value></property>
<property name="automaticTestTable"><value>t_c3p0</value></property>
<property name="testConnectionOnCheckin"><value>true</value></property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="configLocation">
<value>classpath:config.xml</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<!-- <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> -->
</props>
</property>
</bean>
<import resource="applicationContext-dwz.xml" />
<!--<import resource="QuartzConfig.xml" />-->
</beans>
.
config.xml
.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<sqlMap resource="com/dwz/xml/huijin.xml"/>
<sqlMap resource="com/dwz/xml/SchoolGeneral.xml"/>
<sqlMap resource="com/dwz/xml/noviceTeacher.xml"/>
<sqlMap resource="com/dwz/xml/teacherCultivate.xml"/>
<sqlMap resource="com/dwz/xml/studentMaking.xml"/>
<sqlMap resource="com/dwz/xml/schoolSup.xml"/>
<sqlMap resource="com/dwz/xml/honorPrize.xml"/>
<sqlMap resource="com/dwz/xml/campusLife.xml"/>
<sqlMap resource="com/dwz/xml/employmentStatus.xml"/>
</sqlMapConfig>
四,但是提醒一点,service中需要将Exception剖出,这样才会被框架捕捉到,事务才能起作用。Dao层可以直接使用sqlMapClient来调用其中的增删改查的方法,但是必须有上面的config.xml文件的配置
每层的关联都是通过get,set方法关联起来的,所以每个对象都必须有set,get方法