Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
村雨遥
java-learning-demos
提交
81148b88
J
java-learning-demos
项目概览
村雨遥
/
java-learning-demos
上一次同步 1 年多
通知
84
Star
3
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-learning-demos
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
81148b88
编写于
1月 07, 2022
作者:
村雨遥
🎧
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🎉
update springboot-jpa-demo
上级
80ac7b1f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
258 addition
and
0 deletion
+258
-0
springboot-jpa-demo/pom.xml
springboot-jpa-demo/pom.xml
+79
-0
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/SpringbootJpaDemoApplication.java
...cunyu/springbootjpademo/SpringbootJpaDemoApplication.java
+13
-0
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/controller/UserController.java
...om/cunyu/springbootjpademo/controller/UserController.java
+67
-0
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/entity/User.java
...rc/main/java/com/cunyu/springbootjpademo/entity/User.java
+49
-0
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/repository/UserRepository.java
...om/cunyu/springbootjpademo/repository/UserRepository.java
+24
-0
springboot-jpa-demo/src/main/resources/application.yml
springboot-jpa-demo/src/main/resources/application.yml
+13
-0
springboot-jpa-demo/src/test/java/com/cunyu/springbootjpademo/SpringbootJpaDemoApplicationTests.java
.../springbootjpademo/SpringbootJpaDemoApplicationTests.java
+13
-0
未找到文件。
springboot-jpa-demo/pom.xml
0 → 100644
浏览文件 @
81148b88
<?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>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.6.2
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>
com.cunyu
</groupId>
<artifactId>
springboot-jpa-demo
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springboot-jpa-demo
</name>
<description>
springboot-jpa-demo
</description>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.2.8
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<scope>
runtime
</scope>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/SpringbootJpaDemoApplication.java
0 → 100644
浏览文件 @
81148b88
package
com.cunyu.springbootjpademo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
SpringbootJpaDemoApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SpringbootJpaDemoApplication
.
class
,
args
);
}
}
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/controller/UserController.java
0 → 100644
浏览文件 @
81148b88
package
com.cunyu.springbootjpademo.controller
;
import
com.cunyu.springbootjpademo.entity.User
;
import
com.cunyu.springbootjpademo.repository.UserRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* Created with IntelliJ IDEA.
*
* @author : 村雨遥
* @version : 1.0
* @project : springboot-jpa-demo
* @package : com.cunyu.springbootjpademo.controller
* @className : UserController
* @createTime : 2022/1/7 10:55
* @email : 747731461@qq.com
* @微信 : cunyu1024
* @公众号 : 村雨遥
* @网站 : https://cunyu1943.github.io
* @description :
*/
@RestController
@RequestMapping
(
"/user"
)
public
class
UserController
{
@Autowired
private
UserRepository
userRepository
;
/**
* 新增用户
*
* @param user
*/
@PostMapping
(
"/add"
)
public
void
addUser
(
@RequestBody
User
user
)
{
userRepository
.
save
(
user
);
}
/**
* 根据用户 id 删除用户
*
* @param id
*/
@PostMapping
(
"/delete/{id}"
)
public
void
deleteUser
(
@PathVariable
Integer
id
)
{
userRepository
.
deleteById
(
id
);
}
/**
* 更新用户,id 相同则更新,不同则新增
*
* @param user
*/
@PostMapping
(
"/update"
)
public
void
updateUser
(
@RequestBody
User
user
)
{
userRepository
.
save
(
user
);
}
@PostMapping
(
"/query"
)
public
List
<
User
>
queryUsers
()
{
List
<
User
>
userList
=
userRepository
.
findAll
();
return
userList
;
}
}
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/entity/User.java
0 → 100644
浏览文件 @
81148b88
package
com.cunyu.springbootjpademo.entity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
/**
* Created with IntelliJ IDEA.
*
* @author : 村雨遥
* @version : 1.0
* @project : springboot-jpa-demo
* @package : com.cunyu.springbootjpademo.entity
* @className : User
* @createTime : 2022/1/7 10:19
* @email : 747731461@qq.com
* @微信 : cunyu1024
* @公众号 : 村雨遥
* @网站 : https://cunyu1943.github.io
* @description :
*/
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
User
{
@Id
@GeneratedValue
@Column
(
name
=
"id"
)
private
Integer
id
;
@Column
(
name
=
"username"
)
private
String
username
;
@Column
(
name
=
"password"
)
private
String
password
;
@Column
(
name
=
"ch_name"
)
private
String
chName
;
public
User
(
String
username
,
String
password
,
String
chName
)
{
this
.
username
=
username
;
this
.
password
=
password
;
this
.
chName
=
chName
;
}
}
springboot-jpa-demo/src/main/java/com/cunyu/springbootjpademo/repository/UserRepository.java
0 → 100644
浏览文件 @
81148b88
package
com.cunyu.springbootjpademo.repository
;
import
com.cunyu.springbootjpademo.entity.User
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Service
;
/**
* Created with IntelliJ IDEA.
*
* @author : 村雨遥
* @version : 1.0
* @project : springboot-jpa-demo
* @package : com.cunyu.springbootjpademo.repository
* @className : UserRepository
* @createTime : 2022/1/7 10:49
* @email : 747731461@qq.com
* @微信 : cunyu1024
* @公众号 : 村雨遥
* @网站 : https://cunyu1943.github.io
* @description :
*/
@Service
public
interface
UserRepository
extends
JpaRepository
<
User
,
Integer
>
{
}
springboot-jpa-demo/src/main/resources/application.yml
0 → 100644
浏览文件 @
81148b88
server
:
port
:
8080
spring
:
datasource
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://localhost:3306/employee-management?characterEncoding=utf-8
password
:
"
0908"
username
:
root
# type: com.alibaba.druid.pool.DruidDataSource
jpa
:
hibernate
:
ddl-auto
:
update
show-sql
:
true
springboot-jpa-demo/src/test/java/com/cunyu/springbootjpademo/SpringbootJpaDemoApplicationTests.java
0 → 100644
浏览文件 @
81148b88
package
com.cunyu.springbootjpademo
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
SpringbootJpaDemoApplicationTests
{
@Test
void
contextLoads
()
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录