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的四个方法都给它测试一下
测试类
- package com.imooc.sell.service.impl;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class CategoryServiceImplTest {
- @Test
- public void findOne() {
- }
- @Test
- public void findAll() {
- }
- @Test
- public void findByCategoryTypeInTest() {
- }
- @Test
- public void save() {
- }
- }
增加注解
- package com.imooc.sell.service.impl;
- import com.imooc.sell.dataobject.ProductCategory;
- import org.junit.Assert;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.junit4.SpringRunner;
- import static org.junit.Assert.*;
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class CategoryServiceImplTest {
- @Autowired
- private CategoryServiceImpl categoryService;
- @Test
- public void findOne() {
- ProductCategory productCategory = categoryService.findOne(1);
- Assert.assertEquals(new Integer(1),productCategory.getCategoryId());
- }
- @Test
- public void findAll() {
- }
- @Test
- public void findByCategoryTypeInTest() {
- }
- @Test
- public void save() {
- }
- }
com.imooc.sell.dataobject.ProductCategory要增加一个getCategoryId()方法才行
- package com.imooc.sell.dataobject;
- //import javax.persistence.Table;
- import lombok.Data;
- import lombok.Getter;
- import lombok.Setter;
- import lombok.ToString;
- import org.hibernate.annotations.DynamicUpdate;
- import org.hibernate.annotations.Proxy;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import java.util.Date;
- /**
- * 类目
- * Created by zhongzh
- * 2018-05-20 9:31
- * s_product_category
- */
- //@Table(name = "s_product_category")
- @Entity//把数据库映射成对象
- @Proxy(lazy = false)
- @DynamicUpdate //
- @Data//@Data包含生成getter、setter和toString()方法
- //@Getter//如果只是需要Getter那就引入Getter
- //@Setter//如果只是需要Setter那就引入Setter
- //@ToString//如果只是需要ToString那就引入ToString
- public class ProductCategory{
- /** 类目id. */
- @Id//Id是主键,自增类型的。
- //@GeneratedValue//相当于调用了native策略
- //@GeneratedValue(strategy = GenerationType.AUTO)
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer categoryId;//字段名的命名方式也是一样的,把下划线改成为空。
- /** 类目名字. */
- private String categoryName;
- /** 类目编号. */
- private Integer categoryType;
- /** 创建时间. */
- private Date createTime;
- /** 修改时间. */
- private Date updateTime;
- //不要忘了Getter和Setter方法
- /*
- 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;
- }
- 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;
- }
- @Override
- public String toString() {
- return "ProductCategory{" +
- "categoryId=" + categoryId +
- ", categoryName='" + categoryName + '\'' +
- ", categoryType=" + categoryType +
- '}';
- }
- */
- public ProductCategory(String categoryName, Integer categoryType) {
- this.categoryName = categoryName;
- this.categoryType = categoryType;
- }
- public ProductCategory() {
- super();
- }
- public Integer getCategoryId() {
- return categoryId;
- }
- }
- package com.imooc.sell.service.impl;
- import com.imooc.sell.dataobject.ProductCategory;
- import org.junit.Assert;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.junit4.SpringRunner;
- import java.util.Arrays;
- import java.util.List;
- import static org.junit.Assert.*;
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class CategoryServiceImplTest {
- @Autowired
- private CategoryServiceImpl categoryService;
- @Test
- public void findOne() {
- ProductCategory productCategory = categoryService.findOne(10);
- Assert.assertEquals(new Integer(1),productCategory.getCategoryId());
- }
- @Test
- public void findAll() {
- List<ProductCategory> productCategoryList = categoryService.findAll();
- Assert.assertNotEquals(0,((List) productCategoryList).size());//如果集合的总数不等于null,如果productCategoryList的size不等于0,至少是有内容的。
- }
- @Test
- public void findByCategoryTypeInTest() {
- List<ProductCategory> productCategoryList = categoryService.findByCategoryTypeInTest(Arrays.asList(1,2,4));
- Assert.assertNotEquals(0,productCategoryList.size());
- }
- @Test
- public void save() {
- ProductCategory productCategory = new ProductCategory("男生专享",10);
- ProductCategory result = categoryService.save(productCategory);
- Assert.assertNotNull(result);
- }
- }
因为类目并没有给买家端提供专门的接口,所以类目相关Controller层不用再写了。而是商品,下一节开发商品相关的功能。
4-3 买家类目-service的更多相关文章
- 4-2 买家类目-dao(下)
查询出来的对象ProductCategory就已经有updateTime和createTime了,然而你只是把对象的categoryType给修改了一下,修改之后就执行save方法保存了.所以它还是原 ...
- 如何增加亚马逊listing多个类目节点
流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...
- 干货 | 揭秘如何增加listing多个类目节点
流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...
- JAVAEE——宜立方商城03:商品类目选择、Nginx端口或域名区分虚拟机、Nginx反向代理、负载均衡、keepalived实现高可用
1. 学习计划 第三天: 1.商品类目选择(EasyUI的tree实现) 2.图片上传 a) 图片服务器FastDFS(Nainx部分) 2. 商品类目选择 2.1. 原型 2.2. 功能分析 展示商 ...
- 商品类目和商品大广告的Redis缓存
(dubbo)主要的实现类: 商品类目的Redis缓存 com.bjsxt.ego.portal.service.impl.PortalItemCatServiceImpl package com.b ...
- Objective-C中的类目,延展,协议
Objective-C中的类目(Category),延展(Extension),协议(Protocol)这些名词看起来挺牛的,瞬间感觉OC好高大上.在其他OOP语言中就没见过这些名词,刚看到这三个名词 ...
- OC中协议, 类目, 时间, 延展, 属性
只有继承和协议需要引IMPORT "头文件"; 必须接受marryprotocol协议, id<marryprotocol>基于类型的限定, 才能给实例变量赋值 @pr ...
- Objective - C - 添加类目 - NSDate
1.类目为系统内部的类或者是没有源代码的类添加方法,不有添加实例变量 2.添加的方法会成为原类的一部分,子类照样可以使用 3.类目的文件名为原类名+文件名 4.既可以添加实例方法,也可以添加类方法 X ...
- Objective-C学习笔记类目、协议
不是所有的方法都可以被覆盖的!比如:intValue就不能被覆盖!! 原因正在查找中! 别人的电脑上却可以! 类目.h件 #import <Foundation/Foundation.h> ...
随机推荐
- 第十七节:Scrapy爬虫框架之item.py文件以及spider中使用item
Scrapy原理图: item位于原理图的最左边 item.py文件是报存爬取数据的容器,他使用的方法和字典很相似,但是相比字典item多了额外的保护机制,可以避免拼写错误或者定义错误. 1.创建it ...
- UVa 122 树的层次遍历
题意: 给定一颗树, 按层次遍历输出. 分析: 用数组模拟二叉树, bfs即可实现层次遍历 #include <bits/stdc++.h> using namespace std; st ...
- 将json格式转为url参数格式的方法(xjl456852整理修改)
测试页面: <html> <head> <script type="text/javascript" src="jquery-1.11.3. ...
- 关于SELECT 逻辑的执行顺序问题
不会有大多数人都和我一样的认为,是先进行的Where 剔除结果集,再进行Join的吧 SQL server 2014 逻辑执行标准: https://msdn.microsoft.com/en-us/ ...
- 【01】emmet系列之基础介绍
[01]emmet系列之基础介绍 [02]emmet系列之HTML语法 [03]emmet系列之CSS语法 [04]emmet系列之编辑器 [05]emmet系列之各种缩写 相关网址 官网:http: ...
- Fiddler简介与Web抓包,远程抓包(IE、360、谷歌、火狐)
Fiddler简介以及web抓包 一.Fiddler简介 简单来说,Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯.网上简介很多,我们不多说. 二 ...
- msp430入门学习00
在TI官网上找到MSP430的程序例程.数据手册.使用指南等文件.以MSP430F169为例,步骤如下: 1)进入ti官网:http://www.ti.com.cn/ 或者http://www.ti. ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- 51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 http://poj.org/problem?id=1338 首先 ...
- MyBatis 3在Insert之后返回主键
XML: <insert id="addUser" parameterType="User" useGeneratedKeys="true&qu ...