mvc不同的参数获取注解

阅读更多

 

 

不同的参数获取注解

 

重点关注:

 @SessionAttribute---getAtribute(“”);

 

1,从body中获取  @RequestBody 

 

@ApiOperation(value = "保存/修改")

@RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)

public ResultModel saveOrUpdate(//

@Valid @RequestBody ApplyInfoModel applyInfoModel, //

@SessionAttribute("orderNo") String orderNo, //

@SessionAttribute("phone") String phone) {

applyInfoService.saveOrUpdate(applyInfoModel, orderNo, phone);

return new ResultModel<>();

}

 

2,从session中获取    @SessionAttribute

@ApiOperation(value = "查询申请期限")

@RequestMapping(value = "/queryLoanTerm", method = RequestMethod.GET)

public ResultModel> queryLoanTerm(@SessionAttribute("orderNo") String orderNo) {

List response = applyInfoService.queryLoanTerm(orderNo);

return new ResultModel<>(response);

}

3,中param中获取   @RequestParam("orderNo")

@ApiOperation(value = "查询申请期限-传参数")

@RequestMapping(value = "/queryLoanTermWithPara", method = RequestMethod.GET)

public ResultModel> queryLoanTermWithPara(@RequestParam("orderNo") String orderNo) {

List response = applyInfoService.queryLoanTerm(orderNo);

return new ResultModel<>(response);

}

4,从路径中获取  @PathVariable

@ApiOperation(value = "查询证码")

@RequestMapping(value = "/getCode/{phone}", method = RequestMethod.GET)

public ResultModel getCode(@PathVariable String phone) {

WeixinSmsCodeModel model = accountService.getCode(phone);

return new ResultModel<>(model);

}

 

 

 

 

你可能感兴趣的:(spring)