public class ApiBaseAction extends Object
Modifier and Type | Field and Description |
---|---|
protected org.apache.log4j.Logger |
logger |
protected javax.servlet.http.HttpServletRequest |
request
得到request对象
|
protected javax.servlet.http.HttpServletResponse |
response
得到response对象
|
protected TokenService |
tokenService |
Constructor and Description |
---|
ApiBaseAction() |
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
bindException(Exception e)
参数绑定异常
|
String |
getClientIp()
获取请求方IP
|
com.alibaba.fastjson.JSONObject |
getJsonRequest() |
Long |
getUserId()
获取请求的用户Id
|
void |
initBinder(org.springframework.web.bind.WebDataBinder binder,
org.springframework.web.context.request.WebRequest request)
initBinder 初始化绑定
这里处理了3种类型 1、字符串自动 trim 去掉前后空格 2、java.util.Date 转换为 "yyyy-MM-dd HH:mm:ss" 格式 3、java.sql.Date 转换为 "yyyy-MM-dd" 格式 4、java.util.Timestamps 时间转换 |
Map<String,Object> |
toResponseFail(String msg) |
Map<String,Object> |
toResponseSuccess(Object data) |
Map<String,Object> |
toResponseSuccess(String msg) |
Map<String,Object> |
toResponseSuccessForSelect(Object data) |
Map<String,Object> |
toResponsObject(int requestCode,
String msg,
Object data) |
protected org.apache.log4j.Logger logger
@Autowired protected javax.servlet.http.HttpServletRequest request
@Autowired protected javax.servlet.http.HttpServletResponse response
@Autowired protected TokenService tokenService
@ExceptionHandler(value={org.springframework.validation.BindException.class,org.springframework.web.bind.MissingServletRequestParameterException.class,org.apache.shiro.authz.UnauthorizedException.class,org.springframework.beans.TypeMismatchException.class}) @ResponseBody public Map<String,Object> bindException(Exception e)
public Map<String,Object> toResponsObject(int requestCode, String msg, Object data)
requestCode
- msg
- data
- @InitBinder public void initBinder(org.springframework.web.bind.WebDataBinder binder, org.springframework.web.context.request.WebRequest request)
binder
- WebDataBinder 要注册的binderrequest
- 前端请求public String getClientIp()
public com.alibaba.fastjson.JSONObject getJsonRequest()
public Long getUserId()
Copyright © 2021. All rights reserved.