买家端类目

我们默认情况下,表名是product_category,对应的类名就是ProductCategory。

但是如果表名和类名不是这样对应呢?比如表名是s_product_category,那么就需要在类名上加@Table(name="s_product_category")

首先写dataObject:

@Id代表是主键

@GeneratedValue代表自增

@Entity代表这是实体类,和数据库映射

@Dynamic动态生成Update语句,代表更灵活的更新而不是所有都更新

@Transactional如果加在测试方法上面,表明每次执行了test以后都会把数据复原。

package com.ouyan.sell.dataObject;


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

/**
 * 类目
 * @ Author     :Jump
 * @ Date       :Created in 21:13 2018/5/30
 */
@Entity
public class ProductCategory {

    /* 类目id */
    @Id
    @GeneratedValue
    private Integer categoryId;

    /* 类目名字 */
    private String categoryName;

    /* 类目编号 */
    private Integer categoryType;

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public Integer getCategoryType() {
        return categoryType;
    }

    public void setCategoryType(Integer categoryType) {
        this.categoryType = categoryType;
    }
}

要注意以下问题:

lombok(就不用写get,set和toString方法了):

1.引入依赖:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

2.安装lombok插件

3.在实体类上面加@Data注解

原文地址:https://www.cnblogs.com/XJJD/p/8734444.html