@Controller和@RestController: RestController = @ResponseBody + @Controller 所有返回都是json类型,无法跳转到jsp页面,但是不用在每个方法前加@ReaponseBody
@ApiOperation 说明:
value:函数说明
notes:函数用途
response:返回值类型
@RequestMapping(value = "/v1/apis", method = RequestMethod.POST)
value:访问路径
method:请求方式
@Validated:配合pojo类中的注解使用@NotBlank,用与校验属性的空值,后面必须加 BindingResult bindingResult
Insert.class:表示插入时校验
@RequestBody 将json 转成对象
@ApiParam(value = "Created api object", required = true)
value:参数说明
required:参数是否能为空
@ApiOperation(value = "创建api", notes = "根据ApisRequestVo请求对象创建api", response = RequestResult.class)
@RequestMapping(value = "/v1/apis", method = RequestMethod.POST)
@ResponseBody
public ModelAndView createApi(
@Validated({Insert.class}) @RequestBody @ApiParam(value = "Created api object",
required = true) ApisRequestVo vo,
BindingResult bindingResult) {
LOGGER.debug("create api ");
RequestResult result = null;
/*
* Map<String, List<String>> errorMsg = parseErrorMsg(bindingResult);
*
* if (errorMsg != null) { result = new RequestResult(); result.setErrorMsg(errorMsg); return
* createModelAndView(result); }
*/
vo.setId(StringUtils.EMPTY);
result = new RequestResult(apiService.createApiService(vo));
return createModelAndView(result);
}
@PathVariable(value = "id", required = true) String id)
用来接收restful请求方式的参数
@ApiOperation(value = "删除api", notes = "根据id删除 api", response = RequestResult.class)
@RequestMapping(value = "/v1/apis/{id}", method = RequestMethod.DELETE)
public ModelAndView deleteApiById(@ApiParam(value = "api Id",
required = true) @PathVariable(value = "id", required = true) String id) {
RequestResult result = new RequestResult(apiService.deleteApi(id));
return createModelAndView(result);
}
@NotBlank(message = "apiId不能为空", groups = { Insert.class, Update.class })
校验参数.配合@Validated使用
@ApiModelProperty(required = true, value = "apiId", dataType = "String" required:是否可以为空
value:属性说明
dataType:属性类型
public class ApisConfig implements Serializable{ private static final long serialVersionUID = 1L; @NotBlank(message = "apiId不能为空", groups = { Insert.class, Update.class })
@ApiModelProperty(required = true, value = "apiId", dataType = "String")
private String apiId;