| ad5081d3  孙向锦
 
初始化项目 | 1
2
3
4
5
6
7
8
9
10
11
12 |   package com.fh.dao;
  
  import java.util.List;
  
  import javax.annotation.Resource;
  
  import org.apache.ibatis.session.ExecutorType;
  import org.apache.ibatis.session.SqlSession;
  import org.apache.ibatis.session.SqlSessionFactory;
  import org.mybatis.spring.SqlSessionTemplate;
  import org.springframework.stereotype.Repository;
  /**
 | 
| ad5081d3  孙向锦
 
初始化项目 | 13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 |    * 修改时间:2015、12、11
   */
  @Repository("daoSupport")
  public class DaoSupport implements DAO {
  
  	@Resource(name = "sqlSessionTemplate")
  	private SqlSessionTemplate sqlSessionTemplate;
  	
  	/**
  	 * 保存对象
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object save(String str, Object obj) throws Exception {
  		return sqlSessionTemplate.insert(str, obj);
  	}
  	
  	/**
  	 * 批量更新
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object batchSave(String str, List objs )throws Exception{
  		return sqlSessionTemplate.insert(str, objs);
  	}
  	
  	/**
  	 * 修改对象
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object update(String str, Object obj) throws Exception {
  		return sqlSessionTemplate.update(str, obj);
  	}
  
  	/**
  	 * 批量更新
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public void batchUpdate(String str, List objs )throws Exception{
  		SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
  		//批量执行器
  		SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
  		try{
  			if(objs!=null){
  				for(int i=0,size=objs.size();i<size;i++){
  					sqlSession.update(str, objs.get(i));
  				}
  				sqlSession.flushStatements();
  				sqlSession.commit();
  				sqlSession.clearCache();
  			}
  		}finally{
  			sqlSession.close();
  		}
  	}
  	
  	/**
  	 * 批量更新
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object batchDelete(String str, List objs )throws Exception{
  		return sqlSessionTemplate.delete(str, objs);
  	}
  	
  	/**
  	 * 删除对象 
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object delete(String str, Object obj) throws Exception {
  		return sqlSessionTemplate.delete(str, obj);
  	}
  	 
  	/**
  	 * 查找对象
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object findForObject(String str, Object obj) throws Exception {
  		return sqlSessionTemplate.selectOne(str, obj);
  	}
  
  	/**
  	 * 查找对象
  	 * @param str
  	 * @param obj
  	 * @return
  	 * @throws Exception
  	 */
  	public Object findForList(String str, Object obj) throws Exception {
  		return sqlSessionTemplate.selectList(str, obj);
  	}
  	
  	public Object findForMap(String str, Object obj, String key, String value) throws Exception {
  		return sqlSessionTemplate.selectMap(str, obj, key);
  	}
  	
  }
 |