3:springboot微信点餐之商品类目
创建javabean
com\imooc\vo\admin\ProductCategory.java
package com.imooc.vo.admin;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import java.util.Date;
/**
* @author: menghaibin
* @create: 2020-02-08 21:59
* @description: 类目表
**/
Table(name = "product_category")
Entity /*jpa 数据库映射成对象*/
DynamicUpdate /*动态的更新修改时间*/
@Data /*需要pom引入lombok插件以及idea安装此插件,自动会有get set tostring方法*/
public class ProductCategory {
/*类目id*/
@Column(name = "category_id")
@Id /*主键*/
@GeneratedValue /*自增长*/
private Integer categoryId;
/*类目名称*/
@Column(name = "category_name")
private String categoryName;
/*类目编号*/
@Column(name = "category_type")
private Integer categoryType;
/*创建时间*/
@Column(name = "create_time")
private Date createTime;
/*修改时间*/
@Column(name = "update_time")
private Date updateTime;
}
创建dao层接口
com\imooc\dao\ProductCategoryDao.java
package com.imooc.dao;
import com.imooc.vo.admin.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* @author: menghaibin
* @create: 2020-02-08 22:12
* @description: 类目数据操作层
**/
public interface ProductCategoryDao extends JpaRepository<ProductCategory,Integer>{
/*
在业务上 只查询类目下有商品的类目,所以要先查询商品 筛选出类目
这个list就是筛选的类目编号
*/
List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);
}
测试方法:
@Test
public void findByCategoryTypeInTest(){
List<Integer> list = Arrays.asList(10,20,30);
List<ProductCategory> productCategoryList = productCategoryDao.findByCategoryTypeIn(list);
log.info("数量是:{}",String.valueOf(productCategoryList.size()));
}
创建service层接口
com\imooc\service\ProductCategoryService.java
package com.imooc.service;
import com.imooc.vo.admin.ProductCategory;
import java.util.List;
/**
* Created by Administrator on 2020/2/8.
*/
public interface ProductCategoryService {
/*查询单条记录--卖家端*/
ProductCategory findOne(Integer categoryId);
/*查询所有记录--卖家端*/
List<ProductCategory> findAll();
/*添加或者更新 --卖家端*/
ProductCategory save(ProductCategory productCategory);
/*通过编号list来查询 买家端*/
List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);
}
实现service层接口
com\imooc\service\imp\ProductCategoryServiceImp.java
package com.imooc.service.imp;
import com.imooc.dao.ProductCategoryDao;
import com.imooc.service.ProductCategoryService;
import com.imooc.vo.admin.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service/*添加service注解*/
public class ProductCategoryServiceImp implements ProductCategoryService{
/*注入dao接口*/
@Autowired
private ProductCategoryDao productCategoryDao;
/*查询单条记录--卖家端*/
@Override
public ProductCategory findOne(Integer categoryId) {
return productCategoryDao.findOne(categoryId);
}
/*查询所有记录--卖家端*/
@Override
public List<ProductCategory> findAll() {
return productCategoryDao.findAll();
}
/*添加或者更新 --卖家端*/
@Override
public ProductCategory save(ProductCategory productCategory) {
return productCategoryDao.save(productCategory);
}
/*通过编号list来查询 买家端*/
@Override
public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
return productCategoryDao.findByCategoryTypeIn(categoryTypeList);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。