-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
12 changed files
with
238 additions
and
47 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
25 changes: 25 additions & 0 deletions
25
ddd/multi-layers/src/main/java/org/hzz/controller/TestApi.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,25 @@ | ||
package org.hzz.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.hzz.domain.common.Result; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "测试") | ||
@RequestMapping("/test") | ||
public interface TestApi { | ||
|
||
@Operation(summary = "测试异常接口") | ||
@GetMapping("/exception") | ||
default Result<String> exception() { | ||
throw new RuntimeException("测试异常"); | ||
} | ||
|
||
@Operation(summary = "测试hello接口") | ||
@GetMapping("/hello") | ||
default Result<String> hello() { | ||
return Result.success("hello Q10Viking"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
ddd/multi-layers/src/main/java/org/hzz/controller/TestController.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,46 @@ | ||
package org.hzz.controller; | ||
|
||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import org.hzz.domain.common.Result; | ||
import org.hzz.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.context.request.RequestContextHolder; | ||
import org.springframework.web.context.request.ServletRequestAttributes; | ||
|
||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@RestController | ||
public class TestController implements TestApi{ | ||
|
||
@Autowired | ||
HttpServletRequest request; | ||
|
||
@Operation(summary = "测试request属性注入与方法参数注入") | ||
@ApiResponse(responseCode = "200", description = "测试request属性注入与方法参数注入") | ||
@GetMapping("/request") | ||
public Result<List<String>> request(HttpServletRequest methodParamRequest){ | ||
HttpServletRequest contextRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | ||
System.out.println(this.request == methodParamRequest); | ||
System.out.println(this.request == contextRequest); | ||
System.out.println(methodParamRequest == contextRequest); | ||
|
||
return Result.success( | ||
Arrays.asList( | ||
String.format("request: %s, methodParamRequest: %s, contextRequest: %s", | ||
this.request, methodParamRequest, contextRequest), | ||
String.format("request == methodParamRequest: %s, " + | ||
"request == contextRequest: %s, " + | ||
"methodParamRequest == contextRequest: %s", | ||
this.request == methodParamRequest, this.request == contextRequest,methodParamRequest == contextRequest) | ||
) | ||
); | ||
|
||
} | ||
} |
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
10 changes: 8 additions & 2 deletions
10
ddd/multi-layers/src/main/java/org/hzz/domain/common/PageQuery.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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
package org.hzz.domain.common; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PageQuery<T> { | ||
|
||
|
||
@Schema(description = "当前页(默认为1)",example = "1") | ||
private Integer pageNum = 1; | ||
|
||
@Schema(description = "每页行数(默认为20)",example = "20") | ||
private Integer pageSize = 20; | ||
|
||
/** | ||
* 动态查询 | ||
*/ | ||
@Schema(description = "动态查询") | ||
private T query; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.Date; | ||
|
@@ -15,20 +16,26 @@ | |
@AllArgsConstructor | ||
@Builder | ||
public class UserDTO { | ||
@Schema(description = "用户id",example = "1220708537638920191") | ||
private Long id; | ||
|
||
@Schema(description = "用户名",example = "Q10Viking") | ||
@NotBlank(message = "用户名不能为空") | ||
private String username; | ||
|
||
@Schema(description = "用户密码",example = "123456") | ||
@NotBlank(message = "密码不能为空") | ||
private String password; | ||
|
||
@Schema(description = "用户年龄",example = "[email protected]") | ||
@Email(message = "邮箱格式不正确") | ||
@NotNull(message = "邮箱不能为空") | ||
private String email; | ||
|
||
@Schema(description = "用户年龄",example = "18") | ||
private Integer age; | ||
|
||
@Schema(description = "用户手机号",example = "17801054400") | ||
private String phone; | ||
|
||
@Schema(description = "创建时间",example = "2020-01-23 12:23:34") | ||
private Date created; | ||
} |
Oops, something went wrong.