-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(starter-data) 新增-starter-data-rest模块
- Loading branch information
Zhengjiaao
committed
Jun 27, 2022
1 parent
2f1bc3a
commit fef152a
Showing
10 changed files
with
288 additions
and
0 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
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,3 @@ | ||
# starter-data-rest | ||
|
||
官方文档:[starter-data-rest](https://docs.spring.io/spring-data/rest/docs/current/reference/html/#intro-chapter) |
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,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.zja</groupId> | ||
<artifactId>starter-data</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>com.zja</groupId> | ||
<artifactId>starter-data-rest</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-rest-webmvc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-rest</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.29</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ojdbc6</artifactId> | ||
<version>11.2.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.3.4</version> | ||
</dependency> | ||
<!--<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency>--> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid</artifactId> | ||
<version>1.2.9</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<!--swagger3 api docs--> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-boot-starter</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
starter-data/starter-data-rest/src/main/java/com/zja/DataRestApplication.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,24 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-05-22 15:12 | ||
* @Since: | ||
*/ | ||
package com.zja; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* http://localhost:8080/swagger-ui/index.html#/ | ||
*/ | ||
@SpringBootApplication | ||
public class DataRestApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DataRestApplication.class, args); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
starter-data/starter-data-rest/src/main/java/com/zja/config/JpaConfig.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,19 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-02-14 11:12 | ||
* @Since: | ||
*/ | ||
package com.zja.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@Configuration | ||
//@EnableJpaRepositories(basePackages = "com.zja.dao") | ||
@EnableTransactionManagement | ||
public class JpaConfig { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
starter-data/starter-data-rest/src/main/java/com/zja/config/Swagger3Config.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 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2021-10-22 15:17 | ||
* @Since: | ||
*/ | ||
package com.zja.config; | ||
|
||
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.oas.annotations.EnableOpenApi; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
|
||
/** | ||
* http://localhost:port/swagger-ui/index.html#/ | ||
*/ | ||
@EnableOpenApi | ||
@Configuration | ||
public class Swagger3Config { | ||
|
||
@Bean | ||
public Docket createRestApi() { | ||
return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).select() | ||
.apis(RequestHandlerSelectors.basePackage("com.zja")).paths(PathSelectors.any()) | ||
.build(); | ||
} | ||
|
||
private ApiInfo apiInfo() { | ||
return new ApiInfoBuilder().title("提供rest服务").description("我是描述").contact(new Contact("联系人", "www.baidu.com", "[email protected]")) | ||
.version("1.0").build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
starter-data/starter-data-rest/src/main/java/com/zja/dao/UserRepository.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,48 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-02-14 11:04 | ||
* @Since: | ||
*/ | ||
package com.zja.dao; | ||
|
||
import com.zja.entitys.UserEntity; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
import org.springframework.data.rest.core.annotation.RestResource; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 查看所有方法路径:http://localhost:8080/api/user/search 或 http://localhost:8080/${server.servlet.context-path}/api/user/search | ||
*/ | ||
@RepositoryRestResource(path = "user") // 可选的 http://localhost:8080/api/user/ | ||
@Repository | ||
public interface UserRepository extends PagingAndSortingRepository<UserEntity, Long> { | ||
|
||
/** | ||
* http://localhost:8080/api/user/search/findByUserName | ||
*/ | ||
List<UserEntity> findByUserName(String userName); | ||
|
||
/** | ||
* http://localhost:8080/api/user/search/username | ||
*/ | ||
// @RestResource(path = "username", rel = "username") | ||
// List<UserEntity> findByUserName(String userName); | ||
|
||
/** | ||
* http://localhost:8080/api/age/search/findByAge | ||
*/ | ||
@RestResource(path = "age") | ||
List<UserEntity> findByAge(Integer age); | ||
|
||
@RestResource(path = "userNameStartsWith", rel = "userNameStartsWith") | ||
Page findByUserNameStartsWith(@Param("username") String userName, Pageable p); | ||
} |
37 changes: 37 additions & 0 deletions
37
starter-data/starter-data-rest/src/main/java/com/zja/entitys/UserEntity.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,37 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-02-14 11:03 | ||
* @Since: | ||
*/ | ||
package com.zja.entitys; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import lombok.Data; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import java.util.Date; | ||
|
||
@Data | ||
@Entity | ||
@Table(name = "t_user") | ||
@ApiModel("用户信息实体类") | ||
public class UserEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
@ApiModelProperty("唯一标识 ID") | ||
private Long id; | ||
@ApiModelProperty("用户名") | ||
private String userName; | ||
@ApiModelProperty("年龄") | ||
private Integer age; | ||
@ApiModelProperty("创建时间") | ||
private Date createTime; | ||
} |
22 changes: 22 additions & 0 deletions
22
starter-data/starter-data-rest/src/main/resources/application.yaml
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,22 @@ | ||
server: | ||
port: 8080 | ||
# servlet: | ||
# context-path: /rest | ||
|
||
spring: | ||
datasource: | ||
# mysql | ||
username: test | ||
password: pass | ||
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC #&rewriteBatchedStatements=true | ||
driverClassName: com.mysql.cj.jdbc.Driver | ||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: update | ||
naming: | ||
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl # 驼峰命名策略,示例: userName --> userName,@Column(name = "LICENSENUMBER") --> LICENSENUMBER name变为大写 | ||
data: | ||
rest: | ||
base-path: /api # Spring Data REST 的根 URI | ||
|
10 changes: 10 additions & 0 deletions
10
starter-data/starter-data-rest/src/main/resources/db/init.sql
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,10 @@ | ||
-- 插入数据语句 | ||
|
||
-- 增加用户表数据 | ||
insert into t_user(username,age) values ('小明',21); | ||
insert into t_user(username,age) values ('小刘',22); | ||
insert into t_user(username,age) values ('小王',20); | ||
insert into t_user(username,age) values ('明月',16); | ||
insert into t_user(username,age) values ('秦时',18); | ||
|
||
COMMIT; |