springboot @Validated验证"/>
springboot @Validated验证
controller 中加注解@Validated
@Slf4j
@RestController
@RequestMapping("tag")
public class TagConfigureController {@Resourceprivate TagGetDataHandler getDataHandler;@Resourceprivate TagSaveDataHandler saveDataHandler;/*** 保存标签信息* @param taConfigureVo 标签信息* @return JsonResult*/@PostMapping("/saveData")public JsonResult<Integer> submitApply( @Validated TagConfigureVO taConfigureVo) {log.info("saveData提交的tag参数是:" + taConfigureVo);return saveDataHandler.handler(taConfigureVo);}}
vo 中加校验注解
import java.time.LocalDateTime;import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fy.middleground.subscribe.entity.TagConfigure;import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TagConfigureVO {public TagConfigureVO(TagConfigure tagConfigure) {this.id = String.valueOf(tagConfigure.getId());this.title = tagConfigure.getTitle();this.remark = tagConfigure.getRemark();this.sort = tagConfigure.getSort();this.createTime = tagConfigure.getCreateTime();this.updateTime = tagConfigure.getUpdateTime();}private String id;/*** 标签名称*/@NotBlank(message = "标题不能为空")@Max(message = "长度不超过8个字符",value = 8L)private String title;/*** 排序*/@NotNull(message ="排序不能为空")private Integer sort;/*** 分页-页大小: */@JsonIgnore//不需要作为结果返回的字段加private Long size;/*** 当前页*/@JsonIgnoreprivate Long current;
}
更多推荐
springboot @Validated验证
发布评论