springboot @Validated验证

编程入门 行业动态 更新时间:2024-10-15 00:18:59

<a href=https://www.elefans.com/category/jswz/34/1769943.html style=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验证

本文发布于:2023-11-15 18:55:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1604554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:springboot   Validated

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!