4-3 买家类目-service

DAO:ProductCategory。Service可以简化一些,叫CategoryService。

package com.imooc.sell.service;

import com.imooc.sell.dataobject.ProductCategory;

import java.util.List;

/**
 *  类目
 *  Created by zhongzh
 *  2018-05-26 23:53
 */
public interface CategoryService {
   ProductCategory findOne(Integer categoryId);//管理后台使用
   List<ProductCategory> findAll();//管理后台用的
   List<ProductCategory>  findByCategoryTypeInTest(List<Integer> categoryTypeList);
   //新增和更新都是save方法
    ProductCategory save(ProductCategory productCategory);
}
package com.imooc.sell.service.impl;

import com.imooc.sell.dataobject.ProductCategory;
import com.imooc.sell.repository.ProductCategoryRepository;
import com.imooc.sell.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  Created by zhongzh
 *  2018-05-27 0:02
 */

@Service //Service端要加一个注解
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private ProductCategoryRepository repository;//引入DAO

    @Override
    public ProductCategory findOne(Integer categoryId) {
        return repository.getOne(categoryId);
    }

    @Override
    public List<ProductCategory> findAll() {
        return repository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeInTest(List<Integer> categoryTypeList) {
        return repository.findByCategoryTypeIn(categoryTypeList);
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return repository.save(productCategory);
    }
}

com.imooc.sell.service.impl.CategoryServiceImpl的四个方法都给它测试一下

猜你喜欢

转载自www.cnblogs.com/ZHONGZHENHUA/p/9094846.html
4-3
今日推荐