package com.hx.mybatisTool;
|
|
import com.hx.exception.TipsException;
|
import com.hx.util.StringUtils;
|
|
import java.util.Map;
|
|
/**
|
* mybatis 自定义处理sql语句
|
* @author chenjiahe
|
* @Data: 2020-06-08
|
*/
|
public class SqlSentence {
|
|
private String sqlSentence;
|
|
private Map<String,Object> m;
|
/**排序*/
|
private String orderBy;
|
/**开始页数*/
|
private Integer startPage = 0;
|
/**每页数量*/
|
private Integer pageNum = 0;
|
|
//////////////////////////////////////////////////////////////
|
|
/********************mother****************************/
|
|
public SqlSentence()
|
{
|
|
}
|
|
public SqlSentence(Class c, String where, Map<String, Object> values)
|
{
|
if(StringUtils.isEmpty(where))
|
{
|
throw new TipsException("sql is null");
|
}
|
|
if(values == null)
|
{
|
throw new TipsException("values is null");
|
}
|
|
sqlSentence = "select * from " + c.getSimpleName()+ " where " + where;
|
m = values;
|
}
|
|
public SqlSentence(String where, Map<String, Object> values)
|
{
|
if(StringUtils.isEmpty(where))
|
{
|
throw new TipsException("sql is null");
|
}
|
|
if(values == null)
|
{
|
throw new TipsException("values is null");
|
}
|
|
sqlSentence = where;
|
m = values;
|
}
|
|
|
/**
|
* sql整条语句
|
* @param sql 如:select * from user Where name = #{m.userName} order by age desc
|
* @param values 存放的值如:values.put("userName","ChenJiaHe")
|
*/
|
public void sqlSentence(String sql,Map<String,Object> values) {
|
if(StringUtils.isEmpty(sql))
|
{
|
throw new TipsException("sql is null");
|
}
|
|
if(values == null)
|
{
|
throw new TipsException("values is null");
|
}
|
|
sqlSentence = sql;
|
m = values;
|
}
|
|
|
/************************************************************************/
|
|
public Map<String, Object> getM() {
|
return m;
|
}
|
|
public void setM(Map<String, Object> m) {
|
this.m = m;
|
}
|
|
public String getSqlSentence() {
|
return sqlSentence;
|
}
|
|
public void setSqlSentence(String sqlSentence) {
|
this.sqlSentence = sqlSentence;
|
}
|
|
public String getOrderBy() {
|
return orderBy;
|
}
|
|
public void setOrderBy(String orderBy) {
|
this.orderBy = orderBy;
|
}
|
|
public Integer getStartPage() {
|
return startPage;
|
}
|
|
public void setStartPage(Integer startPage) {
|
this.startPage = startPage;
|
}
|
|
public Integer getPageNum() {
|
return pageNum;
|
}
|
|
public void setPageNum(Integer pageNum) {
|
this.pageNum = pageNum;
|
}
|
|
public Integer getStartIndex()
|
{
|
return (startPage - 1) * pageNum;
|
}
|
|
}
|