springboot2+jpa+oracle实例

 pom.xml



	4.0.0

	com.example
	springboot-jpa-oracle-demo
	0.0.1-SNAPSHOT
	jar

	springboot-jpa-oracle-demo
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.5.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-data-jpa
		
		
			org.springframework.boot
			spring-boot-starter-web
		

        
		   com.oracle
		
		   ojdbc6
		
		   11.2.0.4
		
		  
		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	



  application.properties

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL

spring.datasource.username=test

spring.datasource.password=test

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

  domain:

package com.example.demo.domain;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;

@javax.persistence.Table(name = "t_dynasty")
@javax.persistence.Entity
public class Dynasty {
	/**
	 * 
	 * id
	 * 
	 */

	@Id

	@GenericGenerator(name = "system-uuid", strategy = "uuid")

	@GeneratedValue(generator = "system-uuid")

	@Column(name = "id")

	private String id;

	@Column(name = "name")

	private String name;

	@Column(name = "startYear")

	private String startYear;

	@Column(name = "endYear")

	private String endYear;

	@Column(name = "age")

	private Integer age;

	public String getId() {

		return id;

	}

	public void setId(String id) {

		this.id = id;

	}

	public String getName() {

		return name;

	}

	public void setName(String name) {

		this.name = name;

	}

	public String getStartYear() {

		return startYear;

	}

	public void setStartYear(String startYear) {

		this.startYear = startYear;

	}

	public String getEndYear() {

		return endYear;

	}

	public void setEndYear(String endYear) {

		this.endYear = endYear;

	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

}

  repository:

package com.example.demo.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.demo.domain.Dynasty;

public interface DynastyRepository extends JpaRepository {
}

  controller:

package com.example.demo.web;

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.example.demo.domain.Dynasty;
import com.example.demo.repository.DynastyRepository;

@RestController
@RequestMapping("/dynasty")
public class DynastyController {

	@Autowired
	private DynastyRepository dynastyRepository;

	@RequestMapping("/findAll")
	public List findAll() { 
		List dynastys = dynastyRepository.findAll(); 
		return dynastys; 
	}

	@RequestMapping("/hello")
	public String hello() { 
		return "success"; 
	} 
}

  启动程序

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Demo1Application { 
	public static void main(String[] args) {
		SpringApplication.run(Demo1Application.class, args);
	}
}

  

你可能感兴趣的:(springboot2+jpa+oracle实例)