springboot创建项目 编写dao serviece 和controller

11

  

 

 

 

 

 

package com.imooc.dataobject;

//import javax.persistence.Table;

import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * Created by Administrator on 2019/3/5 0005.
 *   现在表名称是 product_category  刚好默认对应
 *   如果是 db_product_category
 */
//@Table(name = "db_product_category")   这就要写
@Table(name = "product_category") //  表名一致    这行是可以不写的  下划线直接转成驼峰
@Entity   //  数据库映射为对象  必须加这个注解
@DynamicUpdate   //update_time字段  自动更新
@Data  //不用写get set  toString 都有了 了
public class ProductCategory {

    //    数据库的下划线修改为驼峰   类目id
    @Id//主键
    @GeneratedValue//自增类型
    private Integer categoryId;//变量和表名一样  下划线修改驼峰

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

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


    //  不知道为什么增加这2个属性  就无法正常更新时间了
    private Date createTime;   //先不增加  用得到了在增加

    private Date updateTime;



    //pom文件中做一下修改就不用每次生成get  set  toString了
    //1.pom文件中增加<groupId>org.projectlombok</groupId>
    //2.安装插件  setting-》plugin  lombok plugin
    //3.实体类开头增加注释@Data  爆红色  就需要刷新pom文件


//    public Date getCreateTime() {
//        return createTime;
//    }
//
//    public void setCreateTime(Date createTime) {
//        this.createTime = createTime;
//    }
//
//    public Date getUpdateTime() {
//        return updateTime;
//    }
//
//    public void setUpdateTime(Date updateTime) {
//        this.updateTime = updateTime;
//    }
//
//
//    //    get  set
//
//
//    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;
//    }


//    @Override
//    public String toString() {
//        return "ProductCategory{" +
//                "categoryId=" + categoryId +
//                ", categoryName='" + categoryName + '\'' +
//                ", categoryType=" + categoryType +
//
//                '}';
//    }
}

 

repository  就是dao

 

package com.imooc.repository;

import com.imooc.dataobject.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
 * Created by Administrator on 2019/3/5 0005.
 *       类名有点长别写错了     不知道为什么老是强调这个 ....
 */
//  这里是interface 不是class    spring的Jpa我以前有讲过  springJpa有一个在慕课网上有自己看吧
public interface ProductCategoryRepository  extends JpaRepository<ProductCategory,Integer> {
//选中接口->GoTo->Test->选中ok     这样就可以进行单元测试了


    //默认存在的方法是无法满足需求的   需要自定义一些方法           //这个是categoryType   不是categoryId!!!!!!
    List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);//根据传入的categroyTypeList查询出类目list
    //findBy  有提示的   CategoryTypeIn  有提示的  拆成多个就有提示了
    //List<ProductCategory> findByCategoryTypeInAndCategoryName();

}

 

findOne

save   保存和更新都是这个方法

 

 

  

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值