三、Api模块
路径:com/imooc/controller/ItemController.java
package com.imooc.controller;
import com.imooc.enums.YesOrNo;
import com.imooc.pojo.*;
import com.imooc.pojo.vo.CategoryVO;
import com.imooc.pojo.vo.ItemInfoVO;
import com.imooc.pojo.vo.NewItemsVO;
import com.imooc.service.CarouselService;
import com.imooc.service.CategoryService;
import com.imooc.service.ItemService;
import com.imooc.utils.IMOOCJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Api(value = "商品接口",tags = "商品信息展示的相关接口")
@RestController
@RequestMapping("item")
public class ItemController {
@Autowired
private ItemService itemService;
@ApiOperation(value="查询商品详情",notes = "查询商品详情",httpMethod = "GET")
@GetMapping("/info/{itemId}")
public IMOOCJSONResult info(
@ApiParam(name = "itemId",value = "商品ID",required = true)
@PathVariable() String itemId) {
if (StringUtils.isBlank(itemId)) {
return IMOOCJSONResult.errorMsg("");
}
Items item = itemService.queryItemById(itemId);
List<ItemsImg> itemImgList=itemService.queryItemImgList(itemId);
List<ItemsSpec> itemSpecList=itemService.queryItemSpecList(itemId);
ItemsParam itemParam=itemService.queryItemParam(itemId);
ItemInfoVO itemInfoVO=new ItemInfoVO();
itemInfoVO.setItem(item);
itemInfoVO.setItemImgList(itemImgList);
itemInfoVO.setItemSpecList(itemSpecList);
itemInfoVO.setItemParam(itemParam);
return IMOOCJSONResult.ok(itemInfoVO);
}
}
四、商品详情VO定义(用户返回到前端)
路径:com/imooc/pojo/vo/ItemInfoVO.java
package com.imooc.pojo.vo;
import com.imooc.pojo.Items;
import com.imooc.pojo.ItemsImg;
import com.imooc.pojo.ItemsParam;
import com.imooc.pojo.ItemsSpec;
import java.util.List;
/**
* 商品详情VO
*/
public class ItemInfoVO {
public Items getItem() {
return item;
}
public void setItem(Items item) {
this.item = item;
}
public List<ItemsImg> getItemImgList() {
return itemImgList;
}
public void setItemImgList(List<ItemsImg> itemImgList) {
this.itemImgList = itemImgList;
}
public List<ItemsSpec> getItemSpecList() {
return itemSpecList;
}
public void setItemSpecList(List<ItemsSpec> itemSpecList) {
this.itemSpecList = itemSpecList;
}
public ItemsParam getItemParam() {
return itemParam;
}
public void setItemParam(ItemsParam itemParam) {
this.itemParam = itemParam;
}
private Items item;
private List<ItemsImg> itemImgList;
private List<ItemsSpec> itemSpecList;
private ItemsParam itemParam;
}