1. 程式人生 > >@ResponseBody的兩種用法

@ResponseBody的兩種用法

第一種用法,方法頭部:

/**
	 * @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;
	}

沒什麼毛病,只是不常見,看起來不太規範,效果是一樣的。