@ResponseBody的兩種用法
阿新 • • 發佈:2018-12-13
第一種用法,方法頭部:
/** * @todo * @param request * @return */ @ResponseBody @RequestMapping(value="model",method = RequestMethod.POST) public Result model(HttpServletRequest request){ Result result = new Result(Result.RESULT_FAILURE,"系統繁忙!"); Param param = (Param) request.getAttribute("param"); JSONObject jobject = JSON.parseObject(param.getData().toString()); result.setTotal(1); result.setData(""); result.setCode(Result.RESULT_SUCCESS); result.setMsg("操作成功!"); return result; }
第二種,方法修飾符後:
/** * @todo * @param request * @return */ @RequestMapping(value="model",method = RequestMethod.POST) public @ResponseBody Result model(HttpServletRequest request){ Result result = new Result(Result.RESULT_FAILURE,"系統繁忙!"); Param param = (Param) request.getAttribute("param"); JSONObject jobject = JSON.parseObject(param.getData().toString()); result.setTotal(1); result.setData(""); result.setCode(Result.RESULT_SUCCESS); result.setMsg("操作成功!"); return result; }
沒什麼毛病,只是不常見,看起來不太規範,效果是一樣的。