This commit is contained in:
yueyuefei 2018-07-30 11:10:26 +08:00
parent 4171e42c97
commit b7cf45ddac
5 changed files with 106 additions and 0 deletions

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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>{
}

View File

@ -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:
# 搜索指定包别名