NutzCN Logo
问答 @Table自动建表的问题
发布于 2382天前 作者 Zhouwt998 3835 次浏览 复制 上一个帖子 下一个帖子
标签:
@Table("user")
public class User {

这样没有自动建表

@Table("use")
public class User {

随便换一个名字就自动建了,这是什么问题。

14 回复

没有建表只能是表已经存在.

18-06-15 12:07:18.341 INFO [main] Select SystemLog as Nutz.Log implement
18-06-15 12:07:18.397 DEBUG [main] Locations count=72 time use 41ms
18-06-15 12:07:18.485 DEBUG [main] Using 95 castor for Castors
18-06-15 12:07:18.535 DEBUG [main] Jdbcs init complete
18-06-15 12:07:18.535 INFO [main] Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
2018-06-15 12:07:18.536  INFO 5784 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-06-15 12:07:18.589  INFO 5784 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
18-06-15 12:07:18.595 DEBUG [main] select expert : org.nutz.dao.impl.jdbc.psql.PsqlJdbcExpert
18-06-15 12:07:18.597 DEBUG [main] JDBC Driver --> 42.2.2
18-06-15 12:07:18.598 DEBUG [main] JDBC Name   --> PostgreSQL JDBC Driver
18-06-15 12:07:18.598 DEBUG [main] JDBC URL    --> jdbc:postgresql://localhost:5432/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
18-06-15 12:07:18.604 DEBUG [main] Database info --> PSQL:[PostgreSQL - 10.1]
18-06-15 12:07:18.610 DEBUG [main] Found 0 resource by src( sqls ) , regex( .(sql|sqlx|sqls)$ )
18-06-15 12:07:18.610 DEBUG [main] SqlManager Sql count=0

没有建表的痕迹,数据库里面也没有

18-06-15 12:08:13.827 DEBUG [main] Found 2 resource by src( com/zgtech/learnnutzdao/model/mapped/ ) , regex( ^.+[.]class$ )
18-06-15 12:08:13.862 DEBUG [main] CREATE TABLE use(
id SERIAL,
name VARCHAR(128),
user_name VARCHAR(128),
pass_word VARCHAR(128),
CONSTRAINT use_pkey PRIMARY KEY (id)
)

这个就有了,好奇怪啊~~

不要用test数据库

贴代码看看

# -Spring Datasource- #
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/student?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    username: postgres
    password:

#- Nutz Dao -#
nutz:
  dao:
    runtime:
      create: true
      migration: false
      basepackage : com.zgtech.learnnutzdao.model.mapped

package com.zgtech.learnnutzdao.model.mapped;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;


/**
 * @author ZwT
 * @date 2018-06-15 9:41
 **/
@Table("user")
public class User {

    @Id
    private Integer id;

    @Column
    @Comment("名称")
    private String name;

    @Comment("用户名")
    @Column(hump = true)
    private String userName;

    @Comment("密码")
    @Column(hump = true)
    private String passWord;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
}

没有这句日志?这个日志应该跟@Table无关的

Found 2 resource by src
2018-06-15 13:00:27.666  INFO 15616 --- [           main] c.z.l.LearnnutzdaoApplication            : Starting LearnnutzdaoApplication on Haier-PC with PID 15616 (E:\WorkCode\learnnutzdao\target\classes started by 12230 in E:\WorkCode\learnnutzdao)
2018-06-15 13:00:27.668  INFO 15616 --- [           main] c.z.l.LearnnutzdaoApplication            : The following profiles are active: dev
2018-06-15 13:00:27.696  INFO 15616 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4f18837a: startup date [Fri Jun 15 13:00:27 CST 2018]; root of context hierarchy
2018-06-15 13:00:28.429  INFO 15616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-06-15 13:00:28.440  INFO 15616 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-06-15 13:00:28.440  INFO 15616 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-06-15 13:00:28.443  INFO 15616 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_161\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;"C:\Program Files\Java\jdk1.8.0_161\bin;C:\Program Files\Java\jdk1.8.0_161\jre\bin";E:\apache-maven-3.5.2\bin;E:\PostgreSQL\pg10\bin;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;E:\Redis;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\WINDOWS\System32\OpenSSH\;C:\Users\12230\AppData\Local\Microsoft\WindowsApps;;.]
2018-06-15 13:00:28.499  INFO 15616 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-06-15 13:00:28.500  INFO 15616 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 805 ms
2018-06-15 13:00:28.566  INFO 15616 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-06-15 13:00:28.568  INFO 15616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-15 13:00:28.569  INFO 15616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-15 13:00:28.569  INFO 15616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-15 13:00:28.569  INFO 15616 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
18-06-15 13:00:28.625 INFO [main] Select SystemLog as Nutz.Log implement
18-06-15 13:00:28.683 DEBUG [main] Locations count=72 time use 44ms
18-06-15 13:00:28.771 DEBUG [main] Using 95 castor for Castors
18-06-15 13:00:28.810 DEBUG [main] Jdbcs init complete
18-06-15 13:00:28.810 INFO [main] Get Connection from DataSource for JdbcExpert, if you lock at here, check your database server and configure
2018-06-15 13:00:28.811  INFO 15616 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2018-06-15 13:00:28.878  INFO 15616 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
18-06-15 13:00:28.883 DEBUG [main] select expert : org.nutz.dao.impl.jdbc.psql.PsqlJdbcExpert
18-06-15 13:00:28.886 DEBUG [main] JDBC Driver --> 42.2.2
18-06-15 13:00:28.887 DEBUG [main] JDBC Name   --> PostgreSQL JDBC Driver
18-06-15 13:00:28.887 DEBUG [main] JDBC URL    --> jdbc:postgresql://localhost:5432/student?useUnicode=true&characterEncoding=UTF-8&useSSL=false
18-06-15 13:00:28.894 DEBUG [main] Database info --> PSQL:[PostgreSQL - 10.1]
18-06-15 13:00:28.898 DEBUG [main] Found 0 resource by src( sqls ) , regex( .(sql|sqlx|sqls)$ )
18-06-15 13:00:28.898 DEBUG [main] SqlManager Sql count=0
2018-06-15 13:00:28.956  INFO 15616 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-15 13:00:29.119  INFO 15616 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4f18837a: startup date [Fri Jun 15 13:00:27 CST 2018]; root of context hierarchy
2018-06-15 13:00:29.155  INFO 15616 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-06-15 13:00:29.156  INFO 15616 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-06-15 13:00:29.169  INFO 15616 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-15 13:00:29.169  INFO 15616 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
18-06-15 13:00:29.216 DEBUG [main] Found 2 resource by src( com/zgtech/learnnutzdao/model/mapped/ ) , regex( ^.+[.]class$ )
2018-06-15 13:00:29.318  INFO 15616 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-06-15 13:00:29.318  INFO 15616 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-06-15 13:00:29.321  INFO 15616 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-06-15 13:00:29.342  INFO 15616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-06-15 13:00:29.344  INFO 15616 --- [           main] c.z.l.LearnnutzdaoApplication            : Started LearnnutzdaoApplication in 1.887 seconds (JVM running for 2.331)

忘记截日志了,您看一下,是有那句日志的

但为什么我只有一个实体,他Found 2 resource?

Found 2 resources 并非指实体数量, 只是说这个目录下有多少个文件

自行调用一下 dao.create(User.class, false) 试试

自行调用也不行,算了,不纠结了,主要换个名字就行,这就很奇怪。谢谢您~

添加回复
请先登陆
回到顶部