Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一缕82年的清风
springboot-learning
提交
c894c9cf
S
springboot-learning
项目概览
一缕82年的清风
/
springboot-learning
通知
601
Star
52
Fork
71
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
springboot-learning
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c894c9cf
编写于
1月 26, 2022
作者:
一缕82年的清风
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[A] JPA代码提交
上级
cae6f57c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
63 addition
and
10 deletion
+63
-10
pom.xml
pom.xml
+6
-0
src/main/java/com/lsqingfeng/springboot/SpringBootLearningApplication.java
.../lsqingfeng/springboot/SpringBootLearningApplication.java
+2
-0
src/main/java/com/lsqingfeng/springboot/controller/JdbcController.java
.../com/lsqingfeng/springboot/controller/JdbcController.java
+6
-1
src/main/java/com/lsqingfeng/springboot/dao/UserDao.java
src/main/java/com/lsqingfeng/springboot/dao/UserDao.java
+10
-0
src/main/java/com/lsqingfeng/springboot/entity/User.java
src/main/java/com/lsqingfeng/springboot/entity/User.java
+16
-0
src/main/java/com/lsqingfeng/springboot/service/UserService.java
...n/java/com/lsqingfeng/springboot/service/UserService.java
+7
-0
src/main/java/com/lsqingfeng/springboot/service/impl/UserServiceImpl.java
...m/lsqingfeng/springboot/service/impl/UserServiceImpl.java
+6
-0
src/main/resources/application.yml
src/main/resources/application.yml
+10
-9
未找到文件。
pom.xml
浏览文件 @
c894c9cf
...
@@ -45,6 +45,12 @@
...
@@ -45,6 +45,12 @@
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- MySQL连接 -->
<!-- MySQL连接 -->
<dependency>
<dependency>
<groupId>
mysql
</groupId>
<groupId>
mysql
</groupId>
...
...
src/main/java/com/lsqingfeng/springboot/SpringBootLearningApplication.java
浏览文件 @
c894c9cf
...
@@ -2,6 +2,7 @@ package com.lsqingfeng.springboot;
...
@@ -2,6 +2,7 @@ package com.lsqingfeng.springboot;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.data.jpa.repository.config.EnableJpaAuditing
;
/**
/**
* @className: SpringBootLearningApplication
* @className: SpringBootLearningApplication
...
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
...
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @date: 2022-01-10 14:36
* @date: 2022-01-10 14:36
*/
*/
@SpringBootApplication
@SpringBootApplication
@EnableJpaAuditing
public
class
SpringBootLearningApplication
{
public
class
SpringBootLearningApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SpringBootLearningApplication
.
class
,
args
);
SpringApplication
.
run
(
SpringBootLearningApplication
.
class
,
args
);
...
...
src/main/java/com/lsqingfeng/springboot/controller/JdbcController.java
浏览文件 @
c894c9cf
...
@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.*;
* @date: 2022-01-17 13:58
* @date: 2022-01-17 13:58
*/
*/
@RestController
@RestController
@RequestMapping
(
"j
dbc
"
)
@RequestMapping
(
"j
pa
"
)
public
class
JdbcController
{
public
class
JdbcController
{
/**
/**
...
@@ -55,4 +55,9 @@ public class JdbcController {
...
@@ -55,4 +55,9 @@ public class JdbcController {
userService
.
delete
(
id
);
userService
.
delete
(
id
);
return
Result
.
success
();
return
Result
.
success
();
}
}
@GetMapping
(
"getByName"
)
public
Result
getByName
(
String
name
){
return
Result
.
success
(
userService
.
getByName
(
name
));
}
}
}
src/main/java/com/lsqingfeng/springboot/dao/UserDao.java
浏览文件 @
c894c9cf
...
@@ -2,8 +2,18 @@ package com.lsqingfeng.springboot.dao;
...
@@ -2,8 +2,18 @@ package com.lsqingfeng.springboot.dao;
import
com.lsqingfeng.springboot.entity.User
;
import
com.lsqingfeng.springboot.entity.User
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
java.io.Serializable
;
import
java.io.Serializable
;
public
interface
UserDao
extends
JpaRepository
<
User
,
Integer
>,
Serializable
{
public
interface
UserDao
extends
JpaRepository
<
User
,
Integer
>,
Serializable
{
/**
*
* @param name
* @return
*/
@Query
(
"select u from User u where u.name = ?1"
)
User
getByName
(
String
name
);
}
}
src/main/java/com/lsqingfeng/springboot/entity/User.java
浏览文件 @
c894c9cf
package
com.lsqingfeng.springboot.entity
;
package
com.lsqingfeng.springboot.entity
;
import
lombok.Data
;
import
lombok.Data
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
javax.persistence.*
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
...
@@ -11,8 +14,15 @@ import java.util.Date;
...
@@ -11,8 +14,15 @@ import java.util.Date;
* @date: 2022-01-14 16:35
* @date: 2022-01-14 16:35
*/
*/
@Data
@Data
@Entity
@Table
(
name
=
"t_user"
)
public
class
User
{
public
class
User
{
/**
* 主键生成策略: 自增
*/
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Integer
id
;
private
Integer
id
;
private
String
name
;
private
String
name
;
...
@@ -21,8 +31,14 @@ public class User {
...
@@ -21,8 +31,14 @@ public class User {
private
String
address
;
private
String
address
;
@CreatedDate
@Column
(
name
=
"create_time"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Date
createTime
;
private
Date
createTime
;
@LastModifiedDate
@Column
(
name
=
"update_time"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Date
updateTime
;
private
Date
updateTime
;
}
}
src/main/java/com/lsqingfeng/springboot/service/UserService.java
浏览文件 @
c894c9cf
...
@@ -46,5 +46,12 @@ public interface UserService {
...
@@ -46,5 +46,12 @@ public interface UserService {
*/
*/
int
delete
(
Integer
id
);
int
delete
(
Integer
id
);
/**
* 根据名字查询
* @param name
* @return
*/
User
getByName
(
String
name
);
}
}
src/main/java/com/lsqingfeng/springboot/service/impl/UserServiceImpl.java
浏览文件 @
c894c9cf
...
@@ -53,4 +53,10 @@ public class UserServiceImpl implements UserService {
...
@@ -53,4 +53,10 @@ public class UserServiceImpl implements UserService {
userDao
.
delete
(
user
);
userDao
.
delete
(
user
);
return
id
;
return
id
;
}
}
@Override
public
User
getByName
(
String
name
)
{
return
userDao
.
getByName
(
name
);
}
}
}
src/main/resources/application.yml
浏览文件 @
c894c9cf
...
@@ -10,15 +10,16 @@ spring:
...
@@ -10,15 +10,16 @@ spring:
jpa
:
jpa
:
show-sql
:
true
# 默认false,在日志里显示执行的sql语句
show-sql
:
true
# 默认false,在日志里显示执行的sql语句
database
:
mysql
database
:
mysql
hibernate.ddl-auto
:
update
#指定为update,每次启动项目检测表结构有变化的时候会新增字段,表不存在时会 新建,如果指定create,则每次启动项目都会清空数据并删除表,再新建
database-platform
:
org.hibernate.dialect.MySQL5Dialect
properties.hibernate.dialect
:
org.hibernate.dialect.MySQL5Dialect
# 使用JPA创建表时,默认使用的存储引擎是MyISAM,通过指定数据库版本,可以使用InnoDB
hibernate
:
database-platform
:
org.hibernate.dialect.MySQL5Dialect
ddl-auto
:
update
#指定为update,每次启动项目检测表结构有变化的时候会新增字段,表不存在时会 新建,如果指定create,则每次启动项目都会清空数据并删除表,再新建
hibernate
:
naming
:
naming
:
#指定jpa的自动表生成策略,驼峰自动映射为下划线格式7
#指定jpa的自动表生成策略,驼峰自动映射为下划线格式
implicit-strategy
:
org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
implicit-strategy
:
org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
#physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
devtools
:
restart
:
enable
:
true
third
:
third
:
weather
:
weather
:
url
:
http://www.baidu.com
url
:
http://www.baidu.com
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录