@RestController
 相当于@Controller+@ResponseBody两个注解的结合,返回json数据,不能返回jsp,html页面。
 @Autowired
 对类成员变量、方法及构造函数进行标注,让 spring 完成 bean 自动装配的工作。
 @PostMapping
 映射一个POST请求。
 @PutMapping
 处理put请求 ,添加的时候使用。
 @DeleteMapping
 处理delete请求,删除操作的时候使用。
 @RequestBody
 请求消息body。
 @Valid
 用于验证注解是否符合要求,直接加在变量user之前,在变量中添加验证信息的要求,当不符合要求时就会在方法中返回message 的错误提示信息。
 @JsonProperty
 此注解用于属性上,作用是把该属性的名称序列化为另外一个名称,如把mainAcct属性序列化为实体的属性main。
 @JsonIgnore
 在实体类向前台返回数据时用来忽略不想传递给前台的属性或接口。
 可以在User类上加上注解@JsonIgnoreProperties(value = “{password}”)
 例如:
 // 忽略参数返回
 @JsonIgnore
 private String names;
 // 用于属性上、set/get方法上,该属性序列化后可重命名。
 @JsonProperty(value=“val”)
 private String values;
实战例子:
@RestController
public class AlternateAcctPowerService {@Autowiredprivate AlternateAcctPowerMapper alternateAcctPowerMapper;@PostMapping(path = "/api/power/alternateAcct", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)public ResultVO alternatePower(@RequestBody @Valid AlternatePowerVO alternatePowerVO){ResultVO resultVO = ResultVO.success("新增代岗权限成功!");try {DateTimeFormatter.ofPattern("yyyyMMdd").parse(alternatePowerVO.getBeginDate());DateTimeFormatter.ofPattern("yyyyMMdd").parse(alternatePowerVO.getEndDate());List<String> fundList = Arrays.asList(alternatePowerVO.getFundCode().split(","));if (fundList.isEmpty()) {resultVO.failure("新增代岗权限失败:组合权限列表为空!");} else {for (String fundCode : fundList) {Map<String, String> powerMap = Maps.newHashMap();powerMap.put("rightId", alternateAcctPowerMapper.getPrimaryKey());powerMap.put("mainAcct", alternatePowerVO.getMainAcct());powerMap.put("rightType", alternatePowerVO.getRightType());powerMap.put("fundCode", fundCode);powerMap.put("alternateAcct", alternatePowerVO.getAlternateAcct());powerMap.put("beginDate", alternatePowerVO.getBeginDate());powerMap.put("endDate", alternatePowerVO.getEndDate());alternateAcctPowerMapper.insertAlternateAcct(powerMap);}}}catch (DateTimeException dte){resultVO.failure("新增代岗权限失败:日期格式不对!");}catch (Exception e){resultVO.failure(String.join("新增代岗权限失败:", e.getMessage()));}return resultVO;}
}@Mapper
@Repository
public interface AlternateAcctPowerMapper {@Select("SELECT SYS_ALTERNATEACCT_RIGHT_SEQ.NEXTVAL FROM DUAL")String getPrimaryKey();int insertAlternateAcct(Map map);
}@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class AlternatePowerVO {@NotBlank(message = "主会计不能为空")@JsonProperty(value = "mainAcct")private String mainAcct;@NotBlank(message = "权限类型不能为空")@JsonProperty(value = "rightType")private String rightType;@NotBlank(message = "组合代码不能为空")@JsonProperty(value = "fundCode")private String fundCode;@NotBlank(message = "待岗人不能为空")@JsonProperty(value = "alternateAcct")private String alternateAcct;@NotBlank(message = "权限生效日期不能为空")@JsonProperty(value = "beginDate")private String beginDate;@NotBlank(message = "权限结束日期不能为空")@JsonProperty(value = "endDate")private String endDate;}@Setter
@Getter
@AllArgsConstructor
public class ResultVO {private RetCode retCode;private String retMsg;@JsonIgnorepublic static ResultVO success(String retMsg) {return new ResultVO(RetCode.REQ_BIZ_SUCCESS, retMsg);}public void failure(String retMsg) {this.retCode = RetCode.REQ_BIZ_FAIL;this.retMsg = retMsg;}
}
@Valid拓展:
 



















