-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3d1ef6
commit 1541d6f
Showing
7 changed files
with
174 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/chentianming11/spring/validation/base/Swagger2Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//package com.github.chentianming11.spring.validation.base; | ||
// | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import springfox.documentation.builders.ApiInfoBuilder; | ||
//import springfox.documentation.builders.PathSelectors; | ||
//import springfox.documentation.builders.RequestHandlerSelectors; | ||
//import springfox.documentation.spi.DocumentationType; | ||
//import springfox.documentation.spring.web.plugins.Docket; | ||
//import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
// | ||
//@Configuration | ||
//@EnableSwagger2 | ||
//public class Swagger2Config { | ||
// | ||
// | ||
// @Bean(value = "defaultApi2") | ||
// public Docket defaultApi2() { | ||
// Docket docket=new Docket(DocumentationType.SWAGGER_2) | ||
// .apiInfo(new ApiInfoBuilder() | ||
// .title("交易助手后台接口文档") | ||
// .description("# helicarrier RESTful APIs") | ||
// .termsOfServiceUrl("http://dora.shtest.ke.com/") | ||
// .version("1.0") | ||
// .build()) | ||
// //分组名称 | ||
// .select() | ||
// //这里指定Controller扫描包路径 | ||
// .apis(RequestHandlerSelectors.basePackage("com.github.chentianming11.spring.validation")) | ||
// .paths(PathSelectors.any()) | ||
// .build(); | ||
// return docket; | ||
// } | ||
//} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/github/chentianming11/spring/validation/controller/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.chentianming11.spring.validation.controller; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author 陈添明 | ||
*/ | ||
@Data | ||
public class Person { | ||
|
||
private Long id; | ||
|
||
private String name; | ||
|
||
private Integer age; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/com/github/chentianming11/spring/validation/controller/PersonController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.github.chentianming11.spring.validation.controller; | ||
|
||
import com.github.chentianming11.spring.validation.base.Result; | ||
import io.swagger.annotations.ApiParam; | ||
import lombok.Data; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.*; | ||
|
||
/** | ||
* @author 陈添明 | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/person") | ||
@Validated | ||
public class PersonController { | ||
|
||
|
||
@Data | ||
public static class SavePerson { | ||
|
||
private Long id; | ||
|
||
@NotNull | ||
@Size(min = 2, max = 10) | ||
private String name; | ||
|
||
@NotNull | ||
@Max(200) | ||
private Integer age; | ||
|
||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$") | ||
private String email; | ||
|
||
} | ||
|
||
@PostMapping("savePerson") | ||
public Result savePerson(@RequestBody @Valid SavePerson savePerson) { | ||
return Result.ok(savePerson); | ||
} | ||
|
||
|
||
@Data | ||
public static class UpdatePerson { | ||
|
||
@NotNull | ||
@Min(1000) | ||
@Max(10000000) | ||
private Long id; | ||
|
||
@Size(min = 2, max = 10) | ||
private String name; | ||
|
||
@Max(200) | ||
private Integer age; | ||
|
||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$") | ||
private String email; | ||
|
||
} | ||
|
||
@PostMapping("updatePerson") | ||
public Result savePerson(@RequestBody @Valid UpdatePerson updatePerson) { | ||
return Result.ok(updatePerson); | ||
} | ||
|
||
|
||
|
||
@GetMapping("queryPerson") | ||
public Result queryPerson(@ApiParam(name = "用户id", example = "10") @NotNull @Min(1000) @Max(10000000) Long id, | ||
@ApiParam(name = "姓名", example = "哈哈") @NotNull @Size(min = 2, max = 10) String name, | ||
@Max(200) Integer age, | ||
@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$") String email) { | ||
|
||
|
||
return Result.ok(); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters