validator-lite-spring

Validator-lite Spring integration component

License

License

GroupId

GroupId

com.viiyue.plugins
ArtifactId

ArtifactId

validator-lite-spring
Last Version

Last Version

1.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

validator-lite-spring
Validator-lite Spring integration component
Source Code Management

Source Code Management

https://github.com/tangxbai/validator-lite-spring.git

Download validator-lite-spring

How to add to project

<!-- https://jarcasting.com/artifacts/com.viiyue.plugins/validator-lite-spring/ -->
<dependency>
    <groupId>com.viiyue.plugins</groupId>
    <artifactId>validator-lite-spring</artifactId>
    <version>1.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.viiyue.plugins/validator-lite-spring/
implementation 'com.viiyue.plugins:validator-lite-spring:1.0.4'
// https://jarcasting.com/artifacts/com.viiyue.plugins/validator-lite-spring/
implementation ("com.viiyue.plugins:validator-lite-spring:1.0.4")
'com.viiyue.plugins:validator-lite-spring:jar:1.0.4'
<dependency org="com.viiyue.plugins" name="validator-lite-spring" rev="1.0.4">
  <artifact name="validator-lite-spring" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.viiyue.plugins', module='validator-lite-spring', version='1.0.4')
)
libraryDependencies += "com.viiyue.plugins" % "validator-lite-spring" % "1.0.4"
[com.viiyue.plugins/validator-lite-spring "1.0.4"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-log4j12 Optional jar 1.7.28
com.viiyue.plugins : validator-lite jar [1.0.0,1.1.0)
org.springframework : spring-webmvc Optional jar [5.0.16,)

provided (1)

Group / Artifact Type Version
javax.servlet : servlet-api jar 2.5

Project Modules

There are no modules declared in this project.

validator-lite-spring

validator-lite-spring version maven central license

validator-lite关于spring的中间件,用于更方便的将validator-lite组件整合到spring框架中。

validator-lite-spring保留了原始spring的验证方式,支持 @Validated 注解开启数据验证,也支持方法BindingResult 参数捕获验证结果,不仅局限于JavaBean的合法性验证,更扩展到了普通参数也可以执行规则校验。

在项目中,你可以使用BindingResult来获取绑定的错误信息,也可以获取关于validator-lite(ValidatedResult)独有的验证结果,此对象中封装的验证结果更为详细明了。

关联文档

关于纯java环境,请移步到:https://github.com/tangxbai/validator-lite

关于整合springboot,请移步到:https://github.com/tangxbai/validator-lite-spring-boot

快速开始

<dependency>
    <groupId>com.viiyue.plugins</groupId>
    <artifactId>validator-lite-spring</artifactId>
    <version>[VERSION]</version>
</dependency>

如何获取最新版本?点击这里获取最新版本

基础配置

仅需要配置一个SpringBean在你的mvc.xml中即可,让spring可以托管这个bean就可以开启验证支持。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    
    <!-- 开启注解驱动模式 -->
    <mvc:annotation-driven/>
    
    <!-- 配置此bean即可开启数据验证支持 -->
    <bean class="com.viiyue.plugins.validator.spring.ValidatorLiteBean" primary="true">
        <property name="configuration.enableSingleMode" value="false"/>
        <property name="configuration.enableStrictMode" value="false"/>
        <property name="configuration.enableWarningLog" value="true"/>
        <property name="configuration.defaultLanguage" value="zh-TW"/>
    </bean>
    
    <!-- 开启Spring的国际化语言配置,此配置同样可以在validator-lite-spring中生效 -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="cacheSeconds" value="1800" />
        <property name="defaultEncoding" value="UTF-8" />
        <property name="useCodeAsDefaultMessage" value="true" />
        <property name="basenames">
            <list>
                <value>classpath:Message</value>
            </list>
        </property>
    </bean>
    
    <!-- 省略你关于其他bean的配置 -->
    ...
</beans>

关于作者

Versions

Version
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0