spring-boot-common

Personal common spring boot utils.

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

io.github.wilson-he
ArtifactId

ArtifactId

spring-boot-common
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

spring-boot-common
Personal common spring boot utils.
Project URL

Project URL

https://github.com/Wilson-He/spring-boot-common
Source Code Management

Source Code Management

https://github.com/Wilson-He/spring-boot-common

Download spring-boot-common

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.wilson-he/spring-boot-common/ -->
<dependency>
    <groupId>io.github.wilson-he</groupId>
    <artifactId>spring-boot-common</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.wilson-he/spring-boot-common/
implementation 'io.github.wilson-he:spring-boot-common:0.1.0'
// https://jarcasting.com/artifacts/io.github.wilson-he/spring-boot-common/
implementation ("io.github.wilson-he:spring-boot-common:0.1.0")
'io.github.wilson-he:spring-boot-common:jar:0.1.0'
<dependency org="io.github.wilson-he" name="spring-boot-common" rev="0.1.0">
  <artifact name="spring-boot-common" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.wilson-he', module='spring-boot-common', version='0.1.0')
)
libraryDependencies += "io.github.wilson-he" % "spring-boot-common" % "0.1.0"
[io.github.wilson-he/spring-boot-common "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.22
org.hibernate.validator : hibernate-validator jar 6.1.0.Final
org.springframework.boot : spring-boot-configuration-processor jar 2.1.6.RELEASE

provided (6)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.30
org.apache.commons : commons-lang3 jar 3.8
org.springframework : spring-web jar 5.3.2
org.springframework : spring-webmvc jar 5.3.2
org.springframework.boot : spring-boot-autoconfigure jar 2.1.6.RELEASE
com.fasterxml.jackson.core : jackson-databind jar 2.10.1

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.6.2
org.junit.jupiter : junit-jupiter-engine jar 5.6.2

Project Modules

There are no modules declared in this project.

web-common-validation

基于Spring Boot 2.0+的个人通用框架。

依赖添加

<dependency>
    <groupId>com.github.wilson.swagger</groupId>
    <artifactId>web-common-validation</artifactId>
    <version>LATEST</version>
</dependency>

快速开始

Application.java

import StringListVO;
import io.swagger.annotations.Api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * Application
 *
 * @author Wilson
 * @since 2018/11/17
 */
@RestController
@RequestMapping("/")
@Api
@SpringBootApplication
@Validated
public class Application {
    public static void main(String[] args) {
	SpringApplication.run(Application.class);
    }

    @GetMapping("/index")
    public String index(@NotBlank @Pattern(regexp = "\\d+") @RequestParam String name){
	return name;
    }
    @GetMapping("/name")
    public String name(@NotBlank @Pattern(regexp = "\\d+",message = "正则错误") @RequestParam String name){
	return name;
    }

    @PostMapping("/vo")
    public String index(@Validated @RequestBody StringListVO vo){
	return "yes";
    }
}

application.yml

web:
  common:
    validation:
      msg-locale: zh_CN  #参数错误返回的信息语种
    #  code-key: code     #参数错误返回码的key字符串命名,默认"code"
    #  msg-key: error     #参数错误返回信息的key字符串命名,默认"msg"
swagger: #swagger自动化配置,需加入swagger2-spring-boot-starter依赖
  enabled: true
  docket:
    base-package: io.github.swagger.demo

效果展示

当同一参数多于1个不符合校验规则则会随机返回一个错误信息,即name参数为空时可能返回"name不能为空"或自定义信息"正则错误"。自定义的校验信息会覆盖原注解固定校验信息,如@NotBlank(message = "名字不能为空")则将返回"名字不能为空",无定义则会返回默认信息:参数名+错误信息(即"name不能为空") get参数校验 post vo校验

Versions

Version
0.1.0
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1