在实体类字段上:
@ApiModelProperty(value="主键")
@Id
private Integer id;
@ApiModelProperty(value="英文名称")
@NotEmpty(message = "英文名字不能为空")
private String name;
@ApiModelProperty(value="中文名称'")
@NotEmpty(message = "中文名字不能为空")
private String nameChs;
@ApiModelProperty(value="状态")
private Boolean status;
@ApiModelProperty(value="创建时间")
private String createTime;
在控制层一定要加上:@Validated
@PostMapping(value="/addBrand")
@ApiOperation(value="新增品牌对象", notes="新增品牌对象")
@Override
public Msg<Brand> addBrandBo(@Validated @RequestBody Brand brand) {
Msg msg=Msg.ok();
try{
Long time =System.currentTimeMillis()/1000;
String timestamp = String.format("%010d", time);
Integer integer=Integer.parseInt(timestamp);
brand.setCreateTime(integer);
brandMapper.insert(brand);
msg.setMessage("添加品牌成功");
msg.setData(brand);
}catch (Exception e){
e.printStackTrace();
}
return msg;
}
Swagger测试: