|
@@ -4,28 +4,41 @@ import com.iamberry.rst.core.page.PagedResult;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.text.ParsePosition;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
+/**
|
|
|
+ * 解决rst列表参数拼接问题
|
|
|
+ */
|
|
|
public class StitchAttrUtil {
|
|
|
|
|
|
+ public static StitchAttrUtil getSa(){
|
|
|
+ return new StitchAttrUtil();
|
|
|
+ }
|
|
|
+
|
|
|
+ private StitchAttrUtil(){
|
|
|
+ propertySet = new HashSet<String>(Arrays.asList(noProperty));
|
|
|
+ timeDateSet = new HashSet<String>(Arrays.asList(timeDate));
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* 组装参数时,会过滤以下参数
|
|
|
* 推荐使用:addNoPro(),添加过滤
|
|
|
*/
|
|
|
- public final static String timeDate[] = {
|
|
|
- "startDate",
|
|
|
- "endDate"
|
|
|
- };
|
|
|
- public static Set<String> timeDateSet = new HashSet<String>(Arrays.asList(timeDate));
|
|
|
-
|
|
|
- public final static String noProperty[] = {
|
|
|
+ private final String timeDate[] = {};
|
|
|
+ /**
|
|
|
+ * 控制时间参数格式
|
|
|
+ * 推荐使用:addDatePro(),添加过滤
|
|
|
+ */
|
|
|
+ private final String noProperty[] = {
|
|
|
"serialVersionUID",
|
|
|
"awaitingSignclosedProductInfoList",
|
|
|
"signclosedProductInfoList"
|
|
|
};
|
|
|
- public static Set<String> propertySet = new HashSet<String>(Arrays.asList(noProperty));
|
|
|
+
|
|
|
+ private SimpleDateFormat sdf = null;
|
|
|
+ private Set<String> propertySet;
|
|
|
+ private Set<String> timeDateSet;
|
|
|
|
|
|
/**
|
|
|
* 组装ModelAndView
|
|
@@ -35,7 +48,7 @@ public class StitchAttrUtil {
|
|
|
* @param pagedResult
|
|
|
* @throws IllegalAccessException
|
|
|
*/
|
|
|
- public static void setModelAndView(Object object, ModelAndView modelAndView, String url, PagedResult<?> pagedResult) {
|
|
|
+ public void setModelAndView(Object object, ModelAndView modelAndView, String url, PagedResult<?> pagedResult) {
|
|
|
StringBuilder sb = new StringBuilder(url);
|
|
|
|
|
|
if(pagedResult.getTotal() != 0) {
|
|
@@ -44,10 +57,10 @@ public class StitchAttrUtil {
|
|
|
|
|
|
sb.append("?pageSize=" + pagedResult.getPageSize());
|
|
|
sb.append("&totalNum=" + pagedResult.getTotal() );
|
|
|
- StitchAttrUtil.setUrlByObj(sb,object);
|
|
|
+ this.setUrlByObj(sb,object);
|
|
|
sb.append("&&pageNO=");
|
|
|
|
|
|
- Map<String, Object> map = StitchAttrUtil.getObjToMap(object);
|
|
|
+ Map<String, Object> map = this.getObjToMap(object);
|
|
|
modelAndView.addAllObjects(map);
|
|
|
|
|
|
modelAndView.addObject("page", pagedResult);
|
|
@@ -63,7 +76,7 @@ public class StitchAttrUtil {
|
|
|
* @return
|
|
|
* @throws IllegalAccessException
|
|
|
*/
|
|
|
- public static Map<String, Object> getObjToMap(Object object) {
|
|
|
+ public Map<String, Object> getObjToMap(Object object) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
Class<?> clazz = object.getClass();
|
|
|
for (Field field : clazz.getDeclaredFields()) {
|
|
@@ -87,7 +100,7 @@ public class StitchAttrUtil {
|
|
|
* @param object
|
|
|
* @throws IllegalAccessException
|
|
|
*/
|
|
|
- public static void setUrlByObj(StringBuilder sb,Object object){
|
|
|
+ public void setUrlByObj(StringBuilder sb,Object object){
|
|
|
Class<?> clazz = object.getClass();
|
|
|
for (Field field : clazz.getDeclaredFields()) {
|
|
|
field.setAccessible(true);
|
|
@@ -98,16 +111,9 @@ public class StitchAttrUtil {
|
|
|
}catch (IllegalAccessException e){
|
|
|
}
|
|
|
if (value != null && !propertySet.contains(fieldName)) {
|
|
|
- if(timeDateSet.contains(fieldName)){
|
|
|
- //Date currentTime = new Date();
|
|
|
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String dateString = formatter.format(value);
|
|
|
- //ParsePosition pos = new ParsePosition(8);
|
|
|
- //Date currentTime = formatter.parse(dateString, pos);
|
|
|
- sb.append("&"+fieldName+ "=" + dateString);
|
|
|
- }else{
|
|
|
- sb.append("&"+fieldName+ "=" + value.toString());
|
|
|
- }
|
|
|
+ if(timeDateSet.contains(fieldName))
|
|
|
+ value = sdf.format(value);
|
|
|
+ sb.append("&"+fieldName+ "=" + value.toString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -116,11 +122,27 @@ public class StitchAttrUtil {
|
|
|
* 添加组装时被过滤的属性名称
|
|
|
* @param pros
|
|
|
*/
|
|
|
- public static void addNoPro(String...pros){
|
|
|
+ public StitchAttrUtil addNoPro(String...pros){
|
|
|
for(String pro : pros){
|
|
|
if(pro != null && !"".equals(pro))
|
|
|
propertySet.add(pro);
|
|
|
}
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加时间参数格式
|
|
|
+ * @param fom //"yyyy-MM-dd HH:mm:ss"
|
|
|
+ * @param pros
|
|
|
+ */
|
|
|
+ public StitchAttrUtil addDatePro(String fom,String...pros){
|
|
|
+ sdf = new SimpleDateFormat(fom);
|
|
|
+ for(String pro : pros){
|
|
|
+ if(pro != null && !"".equals(pro))
|
|
|
+ timeDateSet.add(pro);
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|