-
Notifications
You must be signed in to change notification settings - Fork 297
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
113 changed files
with
5,127 additions
and
38 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
2 changes: 0 additions & 2 deletions
2
...-mysql57-mybatis-plus/src/main/java/tech/pdai/springboot/mysql57/mybatisplus/xml/App.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
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
15 changes: 15 additions & 0 deletions
15
221-springboot-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/App.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,15 @@ | ||
package tech.pdai.springboot.mysql8.jpa; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@SpringBootApplication | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...t-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/config/OpenApiConfig.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,96 @@ | ||
package tech.pdai.springboot.mysql8.jpa.config; | ||
|
||
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpMethod; | ||
import springfox.documentation.builders.*; | ||
import springfox.documentation.oas.annotations.EnableOpenApi; | ||
import springfox.documentation.schema.ScalarType; | ||
import springfox.documentation.service.*; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import tech.pdai.springboot.mysql8.jpa.constants.ResponseStatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* swagger config for open api. | ||
* | ||
* @author pdai | ||
*/ | ||
@Configuration | ||
@EnableOpenApi | ||
public class OpenApiConfig { | ||
|
||
/** | ||
* open api extension by knife4j. | ||
*/ | ||
private final OpenApiExtensionResolver openApiExtensionResolver; | ||
|
||
@Autowired | ||
public OpenApiConfig(OpenApiExtensionResolver openApiExtensionResolver) { | ||
this.openApiExtensionResolver = openApiExtensionResolver; | ||
} | ||
|
||
/** | ||
* @return swagger config | ||
*/ | ||
@Bean | ||
public Docket openApi() { | ||
String groupName = "Test Group"; | ||
return new Docket(DocumentationType.OAS_30) | ||
.groupName(groupName) | ||
.apiInfo(apiInfo()) | ||
.select() | ||
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.globalRequestParameters(getGlobalRequestParameters()) | ||
.globalResponses(HttpMethod.GET, getGlobalResponse()) | ||
.extensions(openApiExtensionResolver.buildExtensions(groupName)) | ||
.extensions(openApiExtensionResolver.buildSettingExtensions()); | ||
} | ||
|
||
/** | ||
* @return global response code->description | ||
*/ | ||
private List<Response> getGlobalResponse() { | ||
return ResponseStatus.HTTP_STATUS_ALL.stream().map( | ||
a -> new ResponseBuilder().code(a.getResponseCode()).description(a.getDescription()).build()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* @return global request parameters | ||
*/ | ||
private List<RequestParameter> getGlobalRequestParameters() { | ||
List<RequestParameter> parameters = new ArrayList<>(); | ||
parameters.add(new RequestParameterBuilder() | ||
.name("AppKey") | ||
.description("App Key") | ||
.required(false) | ||
.in(ParameterType.QUERY) | ||
.query(q -> q.model(m -> m.scalarModel(ScalarType.STRING))) | ||
.required(false) | ||
.build()); | ||
return parameters; | ||
} | ||
|
||
/** | ||
* @return api info | ||
*/ | ||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder() | ||
.title("My API") | ||
.description("test api") | ||
.contact(new Contact("pdai", "http://pdai.tech", "suzhou.daipeng@gmail.com")) | ||
.termsOfServiceUrl("http://xxxxxx.com/") | ||
.version("1.0") | ||
.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...mo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/constants/ResponseStatus.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,40 @@ | ||
package tech.pdai.springboot.mysql8.jpa.constants; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public enum ResponseStatus { | ||
|
||
SUCCESS("200", "success"), | ||
FAIL("500", "failed"), | ||
|
||
HTTP_STATUS_200("200", "ok"), | ||
HTTP_STATUS_400("400", "request error"), | ||
HTTP_STATUS_401("401", "no authentication"), | ||
HTTP_STATUS_403("403", "no authorities"), | ||
HTTP_STATUS_500("500", "server error"); | ||
|
||
public static final List<ResponseStatus> HTTP_STATUS_ALL = Collections.unmodifiableList( | ||
Arrays.asList(HTTP_STATUS_200, HTTP_STATUS_400, HTTP_STATUS_401, HTTP_STATUS_403, HTTP_STATUS_500 | ||
)); | ||
|
||
/** | ||
* response code | ||
*/ | ||
private final String responseCode; | ||
|
||
/** | ||
* description. | ||
*/ | ||
private final String description; | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...o-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/controller/UserController.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,62 @@ | ||
package tech.pdai.springboot.mysql8.jpa.controller; | ||
|
||
|
||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.web.bind.annotation.*; | ||
import tech.pdai.springboot.mysql8.jpa.entity.User; | ||
import tech.pdai.springboot.mysql8.jpa.entity.query.UserQueryBean; | ||
import tech.pdai.springboot.mysql8.jpa.entity.response.ResponseResult; | ||
import tech.pdai.springboot.mysql8.jpa.service.IUserService; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@RestController | ||
@RequestMapping("/user") | ||
public class UserController { | ||
|
||
@Autowired | ||
private IUserService userService; | ||
|
||
/** | ||
* @param user user param | ||
* @return user | ||
*/ | ||
@ApiOperation("Add/Edit User") | ||
@PostMapping("add") | ||
public ResponseResult<User> add(User user) { | ||
if (user.getId()==null || !userService.exists(user.getId())) { | ||
user.setCreateTime(LocalDateTime.now()); | ||
user.setUpdateTime(LocalDateTime.now()); | ||
userService.save(user); | ||
} else { | ||
user.setUpdateTime(LocalDateTime.now()); | ||
userService.update(user); | ||
} | ||
return ResponseResult.success(userService.find(user.getId())); | ||
} | ||
|
||
|
||
/** | ||
* @return user list | ||
*/ | ||
@ApiOperation("Query User One") | ||
@GetMapping("edit/{userId}") | ||
public ResponseResult<User> edit(@PathVariable("userId") Long userId) { | ||
return ResponseResult.success(userService.find(userId)); | ||
} | ||
|
||
/** | ||
* @return user list | ||
*/ | ||
@ApiOperation("Query User Page") | ||
@GetMapping("list") | ||
public ResponseResult<Page<User>> list(@RequestParam int pageSize, @RequestParam int pageNumber) { | ||
return ResponseResult.success(userService.findPage(UserQueryBean.builder().build(), PageRequest.of(pageNumber, pageSize))); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...pringboot-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/dao/IBaseDao.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 tech.pdai.springboot.mysql8.jpa.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.data.repository.NoRepositoryBean; | ||
import tech.pdai.springboot.mysql8.jpa.entity.BaseEntity; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@NoRepositoryBean | ||
public interface IBaseDao<T extends BaseEntity, I extends Serializable> | ||
extends JpaRepository<T, I>, JpaSpecificationExecutor<T> { | ||
} |
12 changes: 12 additions & 0 deletions
12
...pringboot-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/dao/IRoleDao.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,12 @@ | ||
package tech.pdai.springboot.mysql8.jpa.dao; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import tech.pdai.springboot.mysql8.jpa.entity.Role; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@Repository | ||
public interface IRoleDao extends IBaseDao<Role, Long> { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...pringboot-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/dao/IUserDao.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,12 @@ | ||
package tech.pdai.springboot.mysql8.jpa.dao; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import tech.pdai.springboot.mysql8.jpa.entity.User; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
@Repository | ||
public interface IUserDao extends IBaseDao<User, Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...boot-demo-mysql8-jpa/src/main/java/tech/pdai/springboot/mysql8/jpa/entity/BaseEntity.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,9 @@ | ||
package tech.pdai.springboot.mysql8.jpa.entity; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author pdai | ||
*/ | ||
public interface BaseEntity extends Serializable { | ||
} |
Oops, something went wrong.