搭建一个简易的springBoot+SpringDataJpa+Oracle项目
2018-12-07 11:12
393 查看
开发工具:Eclipse+maven
pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <packaging>jar</packaging> <dependencies> <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-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
springBoot启动类
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class StudentApplication { public static void main(String[] args) { SpringApplication.run(StudentApplication.class, args); } }
实体类
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="STUDENT") public class Student { @Id @GeneratedValue private Integer stunum; private Integer age; private String stuname; public Student() { } public Student(Integer stunum, Integer age, String stuname) { this.stunum = stunum; this.age = age; this.stuname = stuname; } public Integer getStunum() { return stunum; } public void setStunum(Integer stunum) { this.stunum = stunum; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } }
DAO
package com.student.dao; import org.springframework.data.jpa.repository.JpaRepository; import com.student.domian.Student; public interface StudentRepository extends JpaRepository<Student,Integer> { }
Controller
package com.student.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.student.dao.StudentRepository; import com.student.domian.Student; @RestController @RequestMapping("/student") public class StudentController { @Autowired private StudentRepository studentRepository; @RequestMapping("/findAll") public List<Student> findAll() { List<Student> students = studentRepository.findAll(); return students; } }
配置文件application.properties
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE spring.datasource.username=yourName spring.datasource.password=yourPassword spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver spring.jpa.properties.hibernate.hbm2ddl.auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect spring.jpa.show-sql= true spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl server.port = 9000
oracle 建表语句
create table student( stunum number(4) primary key, age number(4), stuname varchar2(9) ) insert into student values (1,30,'lisi'); insert into student values (2,31,'zhangsan'); ...
接下来启动和访问:
大工告成!^ ^
相关文章推荐
- 笔记:Spring boot+Thymeleaf+spring-data-jpa简单项目搭建
- springboot+ spring data jpa 项目搭建
- IDEA上面搭建一个SpringBoot的web-mvc项目
- Spring-boot+JPA+Hibernate项目修改数据库MySQL为Oracle出现的问题
- IDEA上面搭建一个SpringBoot的web-mvc项目
- spring + springMVC + spring Data + jpa + maven +(Restful风格) 项目框架搭建(即sssp框架)
- 搭建一个spring-boot项目 2
- SpringBoot(一):快速搭建一个springboot项目
- IDEA上面搭建一个SpringBoot的web-mvc项目
- 跟着和尚一步一步搭建springmvc+springdata-jpa+mybatis+shiro+bootstrap项目(一)
- SpringBoot项目 使用Sprin Data Jpa 操作数据库
- springBoot简介---搭建一个简单的springBoot项目
- 快速搭建一个restful风格的springboot项目
- spring + springMVC + spring Data + jpa + maven 项目框架搭建
- 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(二)
- 在做一个springboot相关的 一个项目的时候,jpa的使用时候发现的一些问题
- SpringBoot 2.x(三):搭建开发环境(整合Spring Data JPA)
- 使用Spring Boot +JPA+mybatis快速启动一个web项目
- 自己动手搭建一个简易的SpringBoot环境
- SpringBoot + Thymeleaf + JPA创建一个web项目