springboot開啟Bean數(shù)據(jù)校驗功能
上篇文章給大家介紹了關于Spring Boot獲取bean的3種方式,今天通過本文給大家介紹在springboot中如何開啟Bean數(shù)據(jù)校驗功能,內(nèi)容如下所示:
①:添加JSR303規(guī)范坐標與Hibernate校驗框架對應坐標
<dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </dependency>
②:對Bean開啟校驗功能
@Component @Data @ConfigurationProperties(prefix = "servers") @Validated public class ServerConfig { }
③:設置校驗規(guī)則
@Component @Data @ConfigurationProperties(prefix = "servers") @Validated public class ServerConfig { @Max(value = 400,message = "最大值不能超過400") private int port; }
小結(jié): 1. 啟用Bean屬性校驗 導入JSR303與Hibernate校驗框架坐標
2.使用@Validated注解啟用校驗功能
3.使用具體校驗規(guī)則規(guī)范數(shù)據(jù)校驗格式
到此這篇關于在springboot中如何開啟Bean數(shù)據(jù)校驗的文章就介紹到這了,更多相關springboot數(shù)據(jù)校驗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
顯示IntelliJ IDEA工具的Run Dashboard功能圖文詳解
這篇文章主要介紹了顯示IntelliJ IDEA工具的Run Dashboard功能,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07servlet之cookie簡介_動力節(jié)點Java學院整理
Cookie技術誕生以來,它就成了廣大網(wǎng)絡用戶和Web開發(fā)人員爭論的一個焦點。下面這篇文章主要給大家介紹了關于servlet之cookie簡介的相關資料,文中介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07詳解Java的MyBatis框架中動態(tài)SQL的基本用法
這篇文章主要介紹了詳解Java的MyBatis框架中動態(tài)SQL的基本用法,文中列出了一些常用SQL動態(tài)語句進行講解,需要的朋友可以參考下2016-04-04