jpa
This commit is contained in:
parent
4171e42c97
commit
b7cf45ddac
6
pom.xml
6
pom.xml
|
|
@ -246,6 +246,12 @@
|
|||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot集成jpa -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.ruoyi.jpaDemo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ruoyi.jpaDemo.pojo.Test;
|
||||
import com.ruoyi.jpaDemo.repository.TestRepository;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("testJpa")
|
||||
public class TestJpaController {
|
||||
|
||||
@Autowired
|
||||
TestRepository testRepository;
|
||||
|
||||
@GetMapping("test")
|
||||
public List<Test> find (){
|
||||
return testRepository.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("save")
|
||||
public void save() {
|
||||
Test test = new Test();
|
||||
test.setName("测试");
|
||||
test.setSex(0);
|
||||
testRepository.save(test);
|
||||
}
|
||||
|
||||
@GetMapping("del")
|
||||
public void del(Long id) {
|
||||
testRepository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.ruoyi.jpaDemo.pojo;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "test")
|
||||
public class Test {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", unique = true, nullable = false)
|
||||
private Long id;
|
||||
@Column
|
||||
private String name;
|
||||
@Column
|
||||
private Integer sex;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Integer getSex() {
|
||||
return sex;
|
||||
}
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.ruoyi.jpaDemo.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.ruoyi.jpaDemo.pojo.Test;
|
||||
|
||||
public interface TestRepository extends JpaRepository<Test, Long>{
|
||||
|
||||
}
|
||||
|
|
@ -48,6 +48,15 @@ spring:
|
|||
restart:
|
||||
#禁用devtools模块的热部署功能
|
||||
enabled: true
|
||||
jpa:
|
||||
database: MYSQL
|
||||
show-sql: true
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL5Dialect
|
||||
# MyBatis
|
||||
mybatis:
|
||||
# 搜索指定包别名
|
||||
|
|
|
|||
Loading…
Reference in New Issue