Skip to content

Commit

Permalink
finished all
Browse files Browse the repository at this point in the history
  • Loading branch information
upangka committed May 22, 2023
1 parent e301656 commit 2c1fbe9
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 28 deletions.
16 changes: 16 additions & 0 deletions ddd/multi-layers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<springdoc.version>1.7.0</springdoc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -24,6 +25,15 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- OpenAPI 3 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi</artifactId>
<version>${springdoc.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -59,6 +69,12 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.hzz.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppSpringdocConfig {

@Bean
public OpenAPI applicationOpenApi() {
Info info = new Info()
.title("分层架构模型")
.description("springboot+mybatis-plus+swagger3")
.version("1.0.0")
.license(new License().name("Apache 2.0").url("https://q10viking.github.io"))
.contact(new Contact().name("q10viking").email("[email protected]"));
return new OpenAPI()
.info(info);
}
}
37 changes: 37 additions & 0 deletions ddd/multi-layers/src/main/java/org/hzz/controller/UserApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.hzz.controller;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.NotImplementedException;
import org.hzz.domain.common.Result;
import org.hzz.domain.dto.UserDTO;
import org.hzz.domain.vo.UserVO;
import org.springframework.web.bind.annotation.*;

import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@RequestMapping("/user")
@Tag(name = "用户管理",description = "用户管理(增删改查)",
externalDocs = @ExternalDocumentation(url = "https://q10viking.github.io",description = "我的博客"))
@Validated
public interface UserApi {

@Operation(summary = "查询用户信息",description = "根据用户id查询用户信息")
@GetMapping("/queryById")
default Result<UserVO> queryById(
@Valid @NotNull @RequestParam(name="userid",required = false)
Long userId){
throw new NotImplementedException("接口未实现");
}


@Operation(summary = "保存用户信息",description = "保存用户信息到数据库")
@PostMapping("/save")
default public Result<String> save(@Valid @RequestBody UserDTO userDTO) {
throw new NotImplementedException("接口未实现");
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package org.hzz.controller;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.hzz.domain.common.PageResult;
import org.hzz.domain.common.Result;
import org.hzz.domain.dto.UserDTO;
import org.hzz.domain.dto.UserQueryDTO;
import org.hzz.domain.vo.UserVO;
import org.hzz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/user")
public class UserController {
public class UserController implements UserApi {

@Autowired
private UserService userService;

@PostMapping("/save")
public Result<String> save( @Valid @RequestBody UserDTO userDTO) {
userService.save(userDTO);
return Result.success("新增用户成功");
}



@PostMapping("/update/{id}")
Expand Down Expand Up @@ -55,4 +54,10 @@ public Result<String> hello() {
public Result<String> exception() {
throw new RuntimeException("测试异常");
}

@Override
public Result<UserVO> queryById(Long userId) {
System.out.println(userId);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ExceptionHandler extends ResponseEntityExceptionHandler {
*/
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
log.info("异常处理");
if(body == null){
body = Result.error(
status.toString().replaceAll("_"," ").toLowerCase(),
Expand Down
19 changes: 0 additions & 19 deletions ddd/multi-layers/src/main/java/org/hzz/domain/App.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class UserDTO {
@NotBlank(message = "用户名不能为空")
private String username;
private String password;

@NotNull(message = "邮箱不能为空")
private String email;

private Date created;
}

0 comments on commit 2c1fbe9

Please sign in to comment.