package com.lsp.baseClass;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description:
* @Author: zhaoyu.cui
* @Date: 16/7/26
* @Time: 下午5:47
*/
public class GenericDaoDefault <E extends Entity> extends SqlSessionDaoSupport implements GenericDao<E> {
private SqlSessionFactory sqlSessionFactory;
protected Class entityClass = GenericUtils.getGenericClass(this.getClass());
public GenericDaoDefault() {
}
protected void checkDaoConfig() {
super.checkDaoConfig();
SqlSession sqlSession = super.getSqlSession();
if(!(sqlSession instanceof SqlSessionTemplate)) {
throw new RuntimeException("the version of this components[ yeepay-persistence ] is not compatable with mybatis-spring.jar version");
} else {
this.sqlSessionFactory = ((SqlSessionTemplate)sqlSession).getSqlSessionFactory();
}
}
public void delete(Serializable id) {
super.getSqlSession().delete(this.getStatementId("delete"), id);
}
public void delete(String ql, Object... args) {
if(args != null && args.length != 0) {
if(args.length == 1) {
super.getSqlSession().delete(this.getStatementId(ql), args[0]);
} else {
HashMap map = new HashMap();
for(int i = 0; i < args.length; ++i) {
map.put("" + i, args[i]);
}
super.getSqlSession().delete(this.getStatementId(ql), map);
}
} else {
super.getSqlSession().delete(this.getStatementId(ql));
}
}
public void delete(E entity) {
this.delete(entity.getId());
}
public E get(Serializable id) {
return (E)super.getSqlSession().selectOne(this.getStatementId("get"), id);
}
public List<E> getAll() {
return super.getSqlSession().selectList(this.getStatementId("getAll"));
}
public List query(String ql, Object... arg) {
List result = null;
if(arg != null && arg.length != 0) {
if(arg.length == 1) {
result = super.getSqlSession().selectList(this.getStatementId(ql), arg[0]);
} else {
HashMap map = new HashMap();
for(int i = 0; i < arg.length; ++i) {
map.put("" + i, arg[i]);
}
result = super.getSqlSession().selectList(this.getStatementId(ql), map);
}
} else {
result = super.getSqlSession().selectList(this.getStatementId(ql));
}
return (List)(result != null?result:new ArrayList());
}
public List query(String sql, int offset, int limit, Object... arg) {
List result = null;
RowBounds rb = new RowBounds(offset, limit);
if(arg != null && arg.length != 0) {
if(arg.length == 1) {
result = this.getSqlSession().selectList(this.getStatementId(sql), arg[0], rb);
} else {
HashMap map = new HashMap();
for(int i = 0; i < arg.length; ++i) {
map.put("" + i, arg[i]);
}
result = this.getSqlSession().selectList(this.getStatementId(sql), map, rb);
}
} else {
result = this.getSqlSession().selectList(this.getStatementId(sql), (Object)null, rb);
}
return (List)(result != null?result:new ArrayList());
}
public Object queryOne(String ql, Object... arg) {
Object ob = null;
if(arg != null && arg.length != 0) {
if(arg.length == 1) {
ob = super.getSqlSession().selectOne(this.getStatementId(ql), arg[0]);
} else {
HashMap map = new HashMap();
for(int i = 0; i < arg.length; ++i) {
map.put("" + i, arg[i]);
}
ob = super.getSqlSession().selectOne(this.getStatementId(ql), map);
}
} else {
ob = super.getSqlSession().selectOne(this.getStatementId(ql));
}
return ob;
}
protected String getStatementId(String postfix) {
return this.entityClass.getSimpleName() + "." + postfix;
}
public void add(E entity) {
super.getSqlSession().insert(this.getStatementId("insert"), entity);
}
public void add(String sql, E entity) {
super.getSqlSession().insert(this.getStatementId(sql), entity);
}
public void update(String ql, Object... arg) {
if(arg != null && arg.length != 0) {
if(arg.length == 1) {
super.getSqlSession().update(this.getStatementId(ql), arg[0]);
} else {
HashMap map = new HashMap();
for(int i = 0; i < arg.length; ++i) {
map.put("" + i, arg[i]);
}
super.getSqlSession().update(this.getStatementId(ql), map);
}
} else {
super.getSqlSession().update(this.getStatementId(ql));
}
}
public Map getMap(String ql, Object... arg) {
Map result = null;
if(arg != null && arg.length != 0) {
if(arg.length == 1) {
result = (Map)super.getSqlSession().selectOne(this.getStatementId(ql), arg[0]);
} else {
HashMap map = new HashMap();
for(int i = 0; i < arg.length; ++i) {
map.put("" + i, arg[i]);
}
result = (Map)super.getSqlSession().selectOne(this.getStatementId(ql), map);
}
} else {
result = (Map)super.getSqlSession().selectOne(this.getStatementId(ql));
}
return result;
}
@Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
super.setSqlSessionFactory(sqlSessionFactory);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
idea 14 ssm 全注解框架+log4j+事物控制+mybatis基础Dao配置 (151个子文件)
GenericDaoDefault.class 6KB
GenericDaoDefault.class 6KB
ErrorInterceptor.class 2KB
ErrorInterceptor.class 2KB
ErrorInterceptor.class 2KB
ErrorInterceptor.class 2KB
UserServiceImpl.class 2KB
UserServiceImpl.class 2KB
UserAction.class 2KB
UserAction.class 2KB
BaseEntity.class 931B
BaseEntity.class 931B
GenericUtils.class 920B
GenericUtils.class 920B
User.class 735B
User.class 735B
UserService.class 387B
UserService.class 387B
Entity.class 367B
Entity.class 367B
GenericDao.class 333B
GenericDao.class 333B
UserMapper.class 263B
UserMapper.class 263B
ssh.iml 5KB
aspectjweaver-1.5.4.jar 1.81MB
spring-core-4.0.2.RELEASE.jar 938KB
freemarker-2.3.19.jar 909KB
mysql-connector-java-5.1.29-bin.jar 856KB
mysql-connector-java-5.1.29-bin.jar 856KB
mysql-connector-java-5.1.29.jar 856KB
spring-context-3.2.6.RELEASE.jar 845KB
struts2-core-2.3.16.jar 788KB
mybatis-3.2.2.jar 683KB
spring-beans-4.0.2.RELEASE.jar 653KB
spring-web-4.0.2.RELEASE.jar 649KB
xwork-core-2.3.16.jar 638KB
javassist-3.11.0.GA.jar 600KB
c3p0-0.9.1.2.jar 596KB
log4j-1.2.17.jar 478KB
spring-jdbc-4.0.2.RELEASE.jar 410KB
jstl-1.2.jar 405KB
spring-aop-4.0.2.RELEASE.jar 344KB
commons-lang3-3.1.jar 308KB
cglib-2.2.2.jar 280KB
spring-tx-4.0.2.RELEASE.jar 242KB
ognl-3.0.6.jar 223KB
spring-expression-3.2.6.RELEASE.jar 193KB
commons-io-2.2.jar 170KB
commons-fileupload-1.3.jar 67KB
struts2-convention-plugin-2.3.16.jar 66KB
commons-logging-1.1.3.jar 61KB
mybatis-spring-1.2.2.jar 48KB
struts2-config-browser-plugin-2.3.16.jar 44KB
asm-3.3.1.jar 43KB
asm-3.3.jar 43KB
asm-commons-3.3.jar 37KB
slf4j-api-1.5.10.jar 23KB
struts2-spring-plugin-2.3.16.jar 21KB
asm-tree-3.3.jar 21KB
jta-1.1.jar 15KB
slf4j-log4j12-1.6.1.jar 10KB
aopalliance-1.0.jar 4KB
GenericDaoDefault.java 6KB
ErrorInterceptor.java 2KB
ErrorInterceptor.java 2KB
UserAction.java 1KB
UserServiceImpl.java 994B
GenericUtils.java 767B
User.java 535B
BaseEntity.java 463B
UserService.java 333B
GenericDao.java 300B
Entity.java 275B
UserMapper.java 190B
success.jsp 479B
success.jsp 479B
index.jsp 365B
index.jsp 365B
register.jsp 356B
register.jsp 356B
404.jsp 210B
404.jsp 210B
output.log 305KB
MANIFEST.MF 100B
.name 3B
pom.properties 102B
ssh-1.0-SNAPSHOT.war 12.81MB
workspace.xml 50KB
uiDesigner.xml 9KB
pom.xml 5KB
ssh_war_exploded.xml 4KB
beans.xml 4KB
beans.xml 4KB
beans.xml 4KB
struts.xml 3KB
struts.xml 3KB
struts.xml 3KB
misc.xml 2KB
web.xml 1KB
共 151 条
- 1
- 2
资源评论
- shx_凌云2018-03-26不错不错。。
qqhr_czy
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Win64OpenSSL-3-3-0.exe
- 课高分程设计-基于C++实现的民航飞行与地图简易管理系统-南京航空航天大学
- 航天器遥测数据故障检测系统python源码+文档说明+数据库(课程设计)
- 北京航空航天大学操作系统课设+ppt+实验报告
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
- 基于单片机的风力发电机转速控制源码
- 基于C++实现的风力发电气动平衡监测系统+源代码+测量数据(高分课程设计)
- 毕业设计- 基于STM32F103C8T6 单片机,物联网技术的太阳能发电装置+源代码+文档说明+架构图+界面截图
- 基于 LSTM(长短期记忆)(即改进的循环神经网络)预测风力发电厂中风力涡轮机产生的功率+源代码+文档说明
- 基于stm32f103+空心杯电机+oled按键+运动算法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功