Giter Club home page Giter Club logo

validator-lite-spring's Introduction

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>

关于作者

validator-lite-spring's People

Contributors

tangxbai avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.