转自:https://blog.csdn.net/LQW_java_home/article/details/53079363
首先 你的jpaProperties配置项中要有
- <prop key="hibernate.hbm2ddl.auto">update</prop>
这样就可以直接有对象映射为表结构,实现面向对象向数据库转化。
实体的名字可以和表名字不一样,字段名字和实体的名字也可以不一样。
- package com.shiroweb.entitys;
- import java.util.Date;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name="shiro_user")//设置数据库中表名字
- public class ShiroUser {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
- @Column(name="USER_NAME")<span style="font-family: Arial, Helvetica, sans-serif;">//设置数据库中字段名字,也可以设置长度,是否为空等属性</span>
- private String username;
- @Column(name="PASS_WORD")
- private String password;
- @Column(name="CREATE_DATE")
- private Date createDate;
- @Column(name="USER_ID")
- private String userId;
- public String getUserId() {
- return userId;
- }
- public void setUserId(String userId) {
- this.userId = userId;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- 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;
- }
- public Date getCreateDate() {
- return createDate;
- }
- public void setCreateDate(Date createDate) {
- this.createDate = createDate;
- }
- }