1
0
mirror of https://gitee.com/coder-xiaomo/flashsale synced 2025-09-12 15:01:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

商品列表

This commit is contained in:
2022-03-03 18:44:06 +08:00
parent ab0b78f278
commit 8feb8c078c
6 changed files with 77 additions and 14 deletions

View File

@@ -11,6 +11,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
@Controller("/item")
@RequestMapping("/item")
@@ -53,6 +55,21 @@ public class ItemController extends BaseController {
return CommonReturnType.create(itemVO);
}
// 商品列表页面浏览
@RequestMapping(value = "/list", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType listItem() {
List<ItemModel> itemModelList = itemService.listItem();
// 使用 Stream Api将list内的itemModel转化为ItemVO
List<ItemVO> itemVOList = itemModelList.stream().map(itemModel -> {
ItemVO itemVO = this.convertVOFromModel(itemModel);
return itemVO;
}).collect(Collectors.toList());
return CommonReturnType.create(itemVOList);
}
private ItemVO convertVOFromModel(ItemModel itemModel) {
if (itemModel == null) {
return null;

View File

@@ -2,6 +2,8 @@ package com.cxyxiaomo.flashsale.dao;
import com.cxyxiaomo.flashsale.dataobject.ItemDO;
import java.util.List;
public interface ItemDOMapper {
/**
* This method was generated by MyBatis Generator.
@@ -35,6 +37,8 @@ public interface ItemDOMapper {
*/
ItemDO selectByPrimaryKey(Integer id);
List<ItemDO> listItem();
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_info

View File

@@ -15,8 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class ItemServiceImpl implements ItemService {
@@ -78,7 +78,15 @@ public class ItemServiceImpl implements ItemService {
@Override
public List<ItemModel> listItem() {
return null;
List<ItemDO> itemDOList = itemDOMapper.listItem();
List<ItemModel> itemModelList = itemDOList.stream().map(itemDO -> {
ItemStockDO itemStockDO = itemStockDOMapper.selectByItemId(itemDO.getId());
ItemModel itemModel = this.convertModelFromDataObject(itemDO, itemStockDO);
return itemModel;
}).collect(Collectors.toList());
return itemModelList;
}
@Override

View File

@@ -143,4 +143,10 @@
img_url = #{imgUrl,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="listItem" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from item_info
order by sales DESC
</select>
</mapper>