16 May 2016

Tao table database mysql tự động bằng Hibernate + Spring boot

Tạo Table tự động trong mysql với Hibernate Spring









demo: Run as  > Maven install 

 package com.Hiber.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.beans.factory.annotation.Autowired;

@Entity
@Table(name = "User")
public class Student {

 @Autowired
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private long id;
 
 private String name;

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

spring.datasource.url = jdbc:mysql://localhost:3306/student
spring.datasource.username = root
spring.datasource.password = 1234567
#\u200Espring\u202C.datasource.testWhileIdle = true
#spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect


Successfully !





0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang