diff --git a/src/main/java/com/nis/domain/Page.java b/src/main/java/com/nis/domain/Page.java index a3ad883d3..348b293c0 100644 --- a/src/main/java/com/nis/domain/Page.java +++ b/src/main/java/com/nis/domain/Page.java @@ -53,7 +53,7 @@ public class Page { private String orderBy = ""; // 标准查询有效, 实例: updatedate desc, name asc private String fields ="";//制定资源的字段 - + private String alias = "";//T对应表的别名 private String where; private String funcName = "page"; // 设置点击页码调用的js函数名称,默认为page,在一页有多个分页对象时使用。 @@ -701,6 +701,64 @@ public class Page { } 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 columnList=new ArrayList(); + //所有属性名 + List propertyList=new ArrayList(); + //属性名称为key,字段名称为value + Map columnMap=new HashMap(); + + 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 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 * @Description: 将orderBy的属性名称替换为字段名称 @@ -756,6 +814,63 @@ public class Page { } 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 columnList=new ArrayList(); + //所有属性名 + List propertyList=new ArrayList(); + Map columnMap=new HashMap(); + + 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 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 * @Description: 去掉orderBy中的desc和asc @@ -777,4 +892,22 @@ public class Page { return str; } + + /** + * alias + * @return alias + */ + + public String getAlias() { + return alias; + } + + + /** + * @param alias the alias to set + */ + public void setAlias(String alias) { + this.alias = alias; + } + }