|
|
@@ -5,12 +5,15 @@ import com.mrxu.framework.boot.entity.BaseCode;
|
|
|
import com.mrxu.framework.boot.entity.LayuiPage;
|
|
|
import com.mrxu.framework.boot.entity.PageResult;
|
|
|
import com.mrxu.framework.boot.entity.ResponseObj;
|
|
|
+import com.mrxu.framework.common.util.StrFunc;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class BaseController {
|
|
|
|
|
|
@@ -26,8 +29,54 @@ public class BaseController {
|
|
|
/**
|
|
|
* 获取请求参数
|
|
|
*/
|
|
|
- public String getParameter(String param) {
|
|
|
- return getRequest().getParameter(param);
|
|
|
+ public String getPara(String name) {
|
|
|
+ String result = getRequest().getParameter(name);
|
|
|
+ return result != null && result.length() != 0 ? result : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getPara(String name, String defaultValue) {
|
|
|
+ String result = getRequest().getParameter(name);
|
|
|
+ return result != null && result.length() != 0 ? result : defaultValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String[]> getParaMap() {
|
|
|
+ return getRequest().getParameterMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String[] getParaValues(String name) {
|
|
|
+ return getRequest().getParameterValues(name);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getParaToInt(String name) {
|
|
|
+ return toInt(getRequest().getParameter(name), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getParaToInt(String name, Integer defaultValue) {
|
|
|
+ return toInt(getRequest().getParameter(name), defaultValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long getParaToLong(String name) {
|
|
|
+ return toLong(getRequest().getParameter(name), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long getParaToLong(String name, Long defaultValue) {
|
|
|
+ return toLong(getRequest().getParameter(name), defaultValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean getParaToBoolean(String name) {
|
|
|
+ return toBoolean(getRequest().getParameter(name), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean getParaToBoolean(String name, Boolean defaultValue) {
|
|
|
+ return toBoolean(getRequest().getParameter(name), defaultValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getParaToDate(String name) {
|
|
|
+ return toDate(getRequest().getParameter(name), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getParaToDate(String name, Date defaultValue) {
|
|
|
+ return toDate(getRequest().getParameter(name), defaultValue);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -121,4 +170,54 @@ public class BaseController {
|
|
|
return layuiPage;
|
|
|
}
|
|
|
|
|
|
+ private Date toDate(String value, Date defaultValue) {
|
|
|
+ try {
|
|
|
+ if (StrFunc.isEmpty(value))
|
|
|
+ return defaultValue;
|
|
|
+ return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(value.trim());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("Can not parse the parameter \"" + value + "\" to Date value.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean toBoolean(String value, Boolean defaultValue) {
|
|
|
+ if (StrFunc.isEmpty(value))
|
|
|
+ return defaultValue;
|
|
|
+ value = value.trim().toLowerCase();
|
|
|
+ if ("1".equals(value) || "true".equals(value))
|
|
|
+ return Boolean.TRUE;
|
|
|
+ else if ("0".equals(value) || "false".equals(value))
|
|
|
+ return Boolean.FALSE;
|
|
|
+ throw new RuntimeException("Can not parse the parameter \"" + value + "\" to Boolean value.");
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer toInt(String value, Integer defaultValue) {
|
|
|
+ try {
|
|
|
+ if (StrFunc.isEmpty(value))
|
|
|
+ return defaultValue;
|
|
|
+ value = value.trim();
|
|
|
+ if (value.startsWith("N") || value.startsWith("n"))
|
|
|
+ return -Integer.parseInt(value.substring(1));
|
|
|
+ return Integer.parseInt(value);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ throw new RuntimeException("Can not parse the parameter \"" + value + "\" to Integer value.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long toLong(String value, Long defaultValue) {
|
|
|
+ try {
|
|
|
+ if (StrFunc.isEmpty(value))
|
|
|
+ return defaultValue;
|
|
|
+ value = value.trim();
|
|
|
+ if (value.startsWith("N") || value.startsWith("n"))
|
|
|
+ return -Long.parseLong(value.substring(1));
|
|
|
+ return Long.parseLong(value);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ throw new RuntimeException("Can not parse the parameter \"" + value + "\" to Long value.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|