分页新增alias属性
This commit is contained in:
@@ -53,7 +53,7 @@ public class Page<T> {
|
|||||||
private String orderBy = ""; // 标准查询有效, 实例: updatedate desc, name asc
|
private String orderBy = ""; // 标准查询有效, 实例: updatedate desc, name asc
|
||||||
|
|
||||||
private String fields ="";//制定资源的字段
|
private String fields ="";//制定资源的字段
|
||||||
|
private String alias = "";//T对应表的别名
|
||||||
private String where;
|
private String where;
|
||||||
|
|
||||||
private String funcName = "page"; // 设置点击页码调用的js函数名称,默认为page,在一页有多个分页对象时使用。
|
private String funcName = "page"; // 设置点击页码调用的js函数名称,默认为page,在一页有多个分页对象时使用。
|
||||||
@@ -701,6 +701,64 @@ public class Page<T> {
|
|||||||
}
|
}
|
||||||
return fileds;
|
return fileds;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @Title: getFiledsSql
|
||||||
|
* @Description: 将fields的属性名称替换为字段名称
|
||||||
|
* @param @param mapName
|
||||||
|
* @param @param fileds
|
||||||
|
* @param @return
|
||||||
|
* @param @throws Exception
|
||||||
|
* @return Map 返回类型
|
||||||
|
* @author (DDM)
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
public String getFiledsSql(String tableAlias,String mapName,String fileds) throws Exception{
|
||||||
|
String[] fieldsColoumn=null;
|
||||||
|
String orderByStr="";
|
||||||
|
//所有字段名
|
||||||
|
List<String> columnList=new ArrayList<String>();
|
||||||
|
//所有属性名
|
||||||
|
List<String> propertyList=new ArrayList<String>();
|
||||||
|
//属性名称为key,字段名称为value
|
||||||
|
Map<String, String> columnMap=new HashMap<String, String>();
|
||||||
|
|
||||||
|
if(!StringUtil.isBlank(fileds)){
|
||||||
|
//解析Fileds的字段/属性名称
|
||||||
|
fieldsColoumn=fileds.split(",");
|
||||||
|
|
||||||
|
//从resultMap中获取字段名称和属性名称
|
||||||
|
if(fieldsColoumn != null){
|
||||||
|
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||||
|
ResultMap map= sqlSessionFactory.getConfiguration().getResultMap(mapName+"Map");
|
||||||
|
List<ResultMapping> mapping= map.getResultMappings();
|
||||||
|
for(ResultMapping mapp:mapping){
|
||||||
|
columnList.add(mapp.getColumn().toLowerCase());
|
||||||
|
propertyList.add(mapp.getProperty());
|
||||||
|
columnMap.put(mapp.getProperty(), mapp.getColumn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(fieldsColoumn != null){
|
||||||
|
fileds="";
|
||||||
|
for (String column : fieldsColoumn) {
|
||||||
|
if(!StringUtil.isBlank(column)){
|
||||||
|
column=column.trim();
|
||||||
|
if(columnList.contains(column.toLowerCase())){
|
||||||
|
fileds+=","+(!StringUtil.isBlank(tableAlias)?(tableAlias+"."):"")+column;
|
||||||
|
}else if(propertyList.contains(column)){
|
||||||
|
fileds+=","+(!StringUtil.isBlank(tableAlias)?(tableAlias+"."):"")+columnMap.get(column).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!StringUtil.isBlank(fileds)){
|
||||||
|
fileds=fileds.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return fileds;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @Title: getOrderBySql
|
* @Title: getOrderBySql
|
||||||
* @Description: 将orderBy的属性名称替换为字段名称
|
* @Description: 将orderBy的属性名称替换为字段名称
|
||||||
@@ -756,6 +814,63 @@ public class Page<T> {
|
|||||||
}
|
}
|
||||||
return orderBy;
|
return orderBy;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @Title: getOrderBySql
|
||||||
|
* @Description: 将orderBy的属性名称替换为字段名称
|
||||||
|
* @param @param mapName
|
||||||
|
* @param @param orderBy
|
||||||
|
* @param @return
|
||||||
|
* @param @throws Exception
|
||||||
|
* @return Map 返回类型
|
||||||
|
* @author (DDM)
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
public static String getOrderBySql(String tableAlias,String mapName,String orderBy) throws Exception{
|
||||||
|
String[] orderByColoumn=null;
|
||||||
|
//所有字段名
|
||||||
|
List<String> columnList=new ArrayList<String>();
|
||||||
|
//所有属性名
|
||||||
|
List<String> propertyList=new ArrayList<String>();
|
||||||
|
Map<String, String> columnMap=new HashMap<String, String>();
|
||||||
|
|
||||||
|
if(!StringUtil.isBlank(orderBy)){
|
||||||
|
//解析orderBy的字段/属性名称
|
||||||
|
orderByColoumn=orderBy.split(",");
|
||||||
|
//从resultMap中获取字段名称和属性名称
|
||||||
|
if(orderByColoumn != null){
|
||||||
|
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||||
|
ResultMap map= sqlSessionFactory.getConfiguration().getResultMap(mapName+"Map");
|
||||||
|
List<ResultMapping> mapping= map.getResultMappings();
|
||||||
|
for(ResultMapping mapp:mapping){
|
||||||
|
columnList.add(mapp.getColumn().toLowerCase());
|
||||||
|
propertyList.add(mapp.getProperty());
|
||||||
|
columnMap.put(mapp.getProperty(), mapp.getColumn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(orderByColoumn != null){
|
||||||
|
orderBy="";
|
||||||
|
for (String column : orderByColoumn) {
|
||||||
|
if(!StringUtil.isBlank(column)){
|
||||||
|
if(columnList.contains(replaceOrderBy(column))){
|
||||||
|
orderBy+=","+(!StringUtil.isBlank(tableAlias)?(tableAlias+"."):"")+column;
|
||||||
|
}else if(propertyList.contains(replaceOrderBy(column))){
|
||||||
|
//如果是实体类名字则获取对应数据库名字+排序方式
|
||||||
|
orderBy+=","+(!StringUtil.isBlank(tableAlias)?(tableAlias+"."):"")
|
||||||
|
+columnMap.get(replaceOrderBy(column)).toString()
|
||||||
|
+column.replace(replaceOrderBy(column), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!StringUtil.isBlank(orderBy)){
|
||||||
|
orderBy=orderBy.substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return orderBy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Title: replaceOrderBy
|
* @Title: replaceOrderBy
|
||||||
* @Description: 去掉orderBy中的desc和asc
|
* @Description: 去掉orderBy中的desc和asc
|
||||||
@@ -777,4 +892,22 @@ public class Page<T> {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* alias
|
||||||
|
* @return alias
|
||||||
|
*/
|
||||||
|
|
||||||
|
public String getAlias() {
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param alias the alias to set
|
||||||
|
*/
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
this.alias = alias;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user