【SpringBoot】【Thymeleaf表单数据验证例子】

SpringBoot Thymeleaf表单数据验证简单例子


1.简要说明

  • SpringBoot 框架,Thymeleaf模板,Bean校验api(Bean Validation API), 结合的简单例子,效果是验证结果显示到页面,希望助您快速get到点。
  • 对于Java的Validation API有一些规范如JCP(Java Community Process)一个开放的国际组织,提出了【JSR-303】规范。第三方具体实现提供jar包,可以简单理解为JSR-303是标准的api,有Hibernate Validation实现扩展的注解,还有Spring Validation扩展的注解。
    Notice:Validation 的规范相继出了JSR-303,JSR-349 等有兴趣的可查看官网
    https://www.jcp.org/en/home/index
    本example下载:https://download.csdn.net/download/chuangshijie/85936467

2.代码例子

  1).先从pom.xml开始

  • java 11
  • springboot 2.7.1
  • 下面这几个依赖包不用具体设置默认使用springboot
  • spring-boot-starter-web
  • spring-boot-starter-thymeleaf
  • spring-boot-starter-validation
  • lombok
  • spring-boot-devtools
  • spring-boot-starter-test
    Notice:Maven项目pom中spring-boot-starter-parent 已经管理者相关的很多依赖包(spring-boot-dependencies)想了解可具体看一下maven的标签properties dependencyManagement pluginManagement等
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>SpringBootThymeleafValidation</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootThymeleafValidation</name>
	<description>Demo project for Spring Boot Thymeleaf Validation</description>
	<properties>
		<java.version>11</java.version>
	</properties>
	<dependencies>
	<!-- springmvc 相关依赖包集 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- Thymeleaf模板依赖导入 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<!-- JSR303规范 hibernate-validator扩展实现依赖包导入 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>
		<!-- lombok依赖 -->
		<dependency>
		        <groupId
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值