| | |
| | | package com.hx.common.dao; |
| | | import com.hx.mybatisTool.SqlParam; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | |
| | | /**查询条数 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**查询列表,返回实体类的List |
| | | * @param mapperClass mapper类 |
| | |
| | | |
| | | /**更新,返回更新数量 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int updateWhere(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int updateWhere(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**更新,返回更新数量 |
| | | * @param mapperClass mapper类 |
| | |
| | | |
| | | /**删除,返回删除数量 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int deleteWhere(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int deleteWhere(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**删除,返回删除数量 |
| | | * @param mapperClass mapper类 |
| | |
| | | package com.hx.common.service; |
| | | import com.hx.mybatisTool.SqlParam; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | |
| | | /**查询条数 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**查询列表,返回实体类的List |
| | | * @param mapperClass mapper类 |
| | |
| | | |
| | | /**更新,返回更新数量 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int updateWhere(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int updateWhere(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**更新,返回更新数量 |
| | | * @param mapperClass mapper类 |
| | |
| | | |
| | | /**删除,返回删除数量 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlParam 查询参数类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int deleteWhere(Class<?> mapperClass, SqlParam sqlParam); |
| | | <T extends Serializable> int deleteWhere(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**删除,返回删除数量 |
| | | * @param mapperClass mapper类 |
| | |
| | | package com.hx.common.service.impl; |
| | | |
| | | import com.hx.common.dao.CommonDao; |
| | | import com.hx.mybatisTool.SqlParam; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | /**获取条数*/ |
| | | @Override |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlParam); |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence); |
| | | } |
| | | |
| | | /**获取列表*/ |
| | |
| | | |
| | | /**更新*/ |
| | | @Override |
| | | public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlParam); |
| | | public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence); |
| | | } |
| | | |
| | | /**全部字段更新*/ |
| | |
| | | |
| | | /**删除*/ |
| | | @Override |
| | | public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlParam); |
| | | public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence); |
| | | } |
| | | |
| | | /**删除*/ |
| | |
| | | |
| | | import com.hx.common.dao.CommonDao; |
| | | import com.hx.common.service.CommonService; |
| | | import com.hx.mybatisTool.SqlParam; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | /**获取条数*/ |
| | | @Override |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return commonDao.selectCount(mapperClass,sqlParam); |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return commonDao.selectCount(mapperClass,sqlSentence); |
| | | } |
| | | |
| | | /**获取列表*/ |
| | |
| | | |
| | | /**更新*/ |
| | | @Override |
| | | public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return commonDao.updateWhere(mapperClass,sqlParam); |
| | | public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return commonDao.updateWhere(mapperClass,sqlSentence); |
| | | } |
| | | |
| | | /**全部字段更新*/ |
| | |
| | | |
| | | /**删除*/ |
| | | @Override |
| | | public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlParam sqlParam) { |
| | | return commonDao.deleteWhere(mapperClass,sqlParam); |
| | | public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return commonDao.deleteWhere(mapperClass,sqlSentence); |
| | | } |
| | | |
| | | /**删除*/ |
| | |
| | | package com.hx.mybatisTool; |
| | | |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.util.SimpleTool; |
| | | import com.hx.util.StringUtils; |
| | | |
| | | import java.util.Map; |
| | |
| | | m = values; |
| | | } |
| | | |
| | | /** |
| | | * 查询的语句 |
| | | * @param sql 如:id = #{m.userId} order by age DESC |
| | | * @param values 存放的值如:values.put("userId","123456") |
| | | */ |
| | | public void sqlWhere(String sql,Map<String,Object> values) { |
| | | if(!SimpleTool.checkNotNull(values)){ |
| | | throw new TipsException("values is null"); |
| | | } |
| | | if(!SimpleTool.checkNotNull(sql)) { |
| | | sql = "1=1"; |
| | | } |
| | | sqlSentence = sql; |
| | | m = values; |
| | | } |
| | | |
| | | /** |
| | | * 更新语句的语句 |
| | | * @param sql 如:name = #{m.name},age = ? WHERE id = #{m.id} |
| | | * @param values 存放的值 |
| | | */ |
| | | public void sqlUpdate(String sql,Map<String,Object> values) { |
| | | if(!SimpleTool.checkNotNull(values)){ |
| | | throw new TipsException("values is null"); |
| | | } |
| | | m = values; |
| | | sqlSentence = sql; |
| | | } |
| | | |
| | | |
| | | /************************************************************************/ |
| | | |
| | |
| | | { |
| | | return (startPage - 1) * pageNum; |
| | | } |
| | | |
| | | } |
| | | |
| | | |