spring boot jpa 无法自动生成表
为啥 create 还不会自动生成表。。实体类也写了
为啥 create 还不会自动生成表。。实体类也写了
2017-01-07
.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ice</groupId> <artifactId>sbTest</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>sbTest Maven Webapp</name> <url>http://maven.apache.org</url> <!-- 直接继承spring-boot-starter-parent成为spring-boot项目 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.3.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!--<hibernate.version>5.1.0.Final</hibernate.version>--> </properties> <dependencies> <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>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <!--用spring官方的thymeleaf模板渲染,src/main/resources/templates/--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--spring-data-jpa做数据库连接--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!--mysql--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
实体类User
package entity; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; /** * Created by ice on 2017/1/7. */ @Entity public class User { @Id @GeneratedValue private Long id; private String name; private String password; 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 String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
.yml文件
server: port: 8888 spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/dbgril username: root password: qwer123 jpa: hibernate: ddl-auto: create show-sql: true
入口
package example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; /** * Created by ice on 2017/1/6. */ @SpringBootApplication @RestController//直接return返回html代码 //@Controller public class DemoAppliaction { public static void main(String[] args) { SpringApplication.run(DemoAppliaction.class,args); } @RequestMapping("/say") public String hello(@RequestParam(value = "name",required = false,defaultValue = "不知道是谁") String name, Model model){ // model.addAttribute("name",name); // return "hello"; return name; } }
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/dbgril username: root password: qwer123 jpa: hibernate: ddl-auto: create show-sql: true
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; /** * Created by ice on 2017/1/7. */ @Entity public class User { @Id @GeneratedValue private Long id;
数据库也建好了,启动也不报错,就是不会自动生成表为啥呢。。
举报