@Entity注解

[@Entity]  
   必须与@Id注解 结合使用  
     否则  No identifier specified for entity:   
   name 属性  
    (可选)实体名称。 缺省为实体类的非限定名称。   
        该名称用于引用查询中的实体。  
        该名称不能是Java持久性查询语言中的保留字面值。  
   
   不与@Table结合的话 表名 默认为 SnakeCaseStrategy(命名策略 )为表名  
    若使用 name属性 且没有与@Table结合 则表名为 name值的SnakeCaseStrategy(命名策略 )  
    例如:  
        @Entity  
            public class UserEntity{...} 表名 user_entity  
        @Entity(name="UE")  
            public class UserEntity{...} 表名 ue  
        @Entity(name="UsEntity")  
            public class UserEntity{...} 表名 us_entity  

package sun.rain.amazing.javax.anno.domain;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * @author   sunRainAmazing
 */
@Entity
@Data
public class UserEntity {
    /**
     *  No identifier specified for entity: sun.rain.amazing.javax.anno.domain.UserEntity
     */
    @Id
    private int id;
    private String username;
    private String email;

    public UserEntity(String username, String email) {
        this.username = username;
        this.email = email;
    }

    public UserEntity() {
    }
}
CREATE TABLE `user_entity` (
  `id` int(11) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `username` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


package sun.rain.amazing.javax.anno.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 *
 * @author sunRainAmazing
 */
@Data
@AllArgsConstructor
@Entity(name="UePro")
public class UserEntityProperty {
    /**
     *  No identifier specified for entity: sun.rain.amazing.javax.anno.domain.UserEntity
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String username;
    private String email;
    private String mobile;

    public UserEntityProperty(String username, String email, String mobile) {
        this.username = username;
        this.email = email;
        this.mobile = mobile;
    }

    public UserEntityProperty() {
    }
}


CREATE TABLE `ue_pro` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) DEFAULT NULL,
  `mobile` varchar(255) DEFAULT NULL,
  `username` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值