mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-10 11:48:14 +08:00
商品列表
This commit is contained in:
parent
ab0b78f278
commit
8feb8c078c
@ -11,7 +11,7 @@
|
||||
Target Server Version : 50726
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 03/03/2022 15:29:13
|
||||
Date: 03/03/2022 18:37:04
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@ -29,12 +29,26 @@ CREATE TABLE `item_info` (
|
||||
`sales` int(11) NOT NULL DEFAULT 0,
|
||||
`img_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of item_info
|
||||
-- ----------------------------
|
||||
INSERT INTO `item_info` VALUES (1, 'item-h7p0wt-22680', 22.00, '0sddhs4aeowc26638j5fp2ox', 0, 'https://domain.com/pic/190ghi.jpg');
|
||||
INSERT INTO `item_info` VALUES (2, '电视机', 1800.00, '一台电视机', 0, 'https://domain.com/pic/television.png');
|
||||
INSERT INTO `item_info` VALUES (3, '电冰箱', 2800.00, '一台电冰箱', 0, 'https://domain.com/pic/电冰箱.png');
|
||||
INSERT INTO `item_info` VALUES (4, '空调', 3600.00, '一台空调', 0, 'https://domain.com/pic/空调.png');
|
||||
INSERT INTO `item_info` VALUES (5, 'item-2xmm6g-5492', 235.00, 'lsudsf67ghobos3q1olbwx27', 0, 'https://domain.com/pic/1fvojf.jpg');
|
||||
INSERT INTO `item_info` VALUES (6, 'item-wlx9gu-1220', 270.00, '3q234qqp3wwo53mtdv0qjuvg', 0, 'https://domain.com/pic/tkxc5q.jpg');
|
||||
INSERT INTO `item_info` VALUES (7, 'item-cqru11-3487', 259.00, '04q6lopvj3ubb4458k4wldok', 0, 'https://domain.com/pic/nxmx2h.jpg');
|
||||
INSERT INTO `item_info` VALUES (8, 'item-7f7qa1-5168', 314.00, 'jqkgc5ks2r9e2k8za3zs9rlc', 0, 'https://domain.com/pic/gvwtzd.jpg');
|
||||
INSERT INTO `item_info` VALUES (9, 'item-i8flrb-7649', 129.00, 'i0m9w2x5w4gugeq7hlyp8nqx', 0, 'https://domain.com/pic/rz85vu.jpg');
|
||||
INSERT INTO `item_info` VALUES (10, 'item-epo4p3-8545', 40.00, 'x71zeodg46ziiid7pgfag4bc', 0, 'https://domain.com/pic/o0f3uk.jpg');
|
||||
INSERT INTO `item_info` VALUES (11, 'item-o7iiuj-1056', 322.00, 'fm3r99ko038jbfhy5cg7kwp8', 0, 'https://domain.com/pic/u0rjr8.jpg');
|
||||
INSERT INTO `item_info` VALUES (12, 'item-fi7q7p-11366', 24.00, '18e54me0cdbqt8n9mxjnisf8', 0, 'https://domain.com/pic/eetb26.jpg');
|
||||
INSERT INTO `item_info` VALUES (13, 'item-9lwcps-12165', 9.00, 'hlxnhcfak89wengpsnehgtqs', 0, 'https://domain.com/pic/r9yxmi.jpg');
|
||||
INSERT INTO `item_info` VALUES (14, 'item-pgdbqk-12664', 151.00, 'irydvab5wixg59c7scgt50yh', 0, 'https://domain.com/pic/xvfgwv.jpg');
|
||||
INSERT INTO `item_info` VALUES (15, 'item-0lq98b-13424', 164.00, 'vwz4rsb4qhsnjs3phos35415', 0, 'https://domain.com/pic/9qhi3l.jpg');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for item_stock
|
||||
@ -47,12 +61,26 @@ CREATE TABLE `item_stock` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `item_id`(`item_id`) USING BTREE,
|
||||
CONSTRAINT `item_stock_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of item_stock
|
||||
-- ----------------------------
|
||||
INSERT INTO `item_stock` VALUES (1, 140, 1);
|
||||
INSERT INTO `item_stock` VALUES (2, 876, 2);
|
||||
INSERT INTO `item_stock` VALUES (3, 876, 3);
|
||||
INSERT INTO `item_stock` VALUES (4, 87, 4);
|
||||
INSERT INTO `item_stock` VALUES (5, 909, 5);
|
||||
INSERT INTO `item_stock` VALUES (6, 960, 6);
|
||||
INSERT INTO `item_stock` VALUES (7, 511, 7);
|
||||
INSERT INTO `item_stock` VALUES (8, 444, 8);
|
||||
INSERT INTO `item_stock` VALUES (9, 116, 9);
|
||||
INSERT INTO `item_stock` VALUES (10, 93, 10);
|
||||
INSERT INTO `item_stock` VALUES (11, 943, 11);
|
||||
INSERT INTO `item_stock` VALUES (12, 917, 12);
|
||||
INSERT INTO `item_stock` VALUES (13, 351, 13);
|
||||
INSERT INTO `item_stock` VALUES (14, 117, 14);
|
||||
INSERT INTO `item_stock` VALUES (15, 34, 15);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user_info
|
||||
|
@ -54,29 +54,29 @@
|
||||
$("#create").on("click", function () {
|
||||
var title = $("#title").val();
|
||||
var description = $("#description").val();
|
||||
var imgUrl = $("#imgUrl").val();
|
||||
var price = $("#price").val();
|
||||
var imgUrl = $("#imgUrl").val();
|
||||
var stock = $("#stock").val();
|
||||
|
||||
if (title == null || title == "") {
|
||||
alert("商品名不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
return false;
|
||||
}
|
||||
if (description == null || description == "") {
|
||||
alert("商品描述不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
}
|
||||
if (imgUrl == null || imgUrl == "") {
|
||||
alert("图片Url不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
return false;
|
||||
}
|
||||
if (price == null || price == "") {
|
||||
alert("价格不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
return false;
|
||||
}
|
||||
if (imgUrl == null || imgUrl == "") {
|
||||
alert("图片Url不能为空");
|
||||
return false;
|
||||
}
|
||||
if (stock == null || stock == "") {
|
||||
alert("库存不能为空");
|
||||
return false; // 捕获onclick事件,不让他传递到上一层
|
||||
return false;
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user