(十)搭建springboot商城--商品热销排行
生活随笔
收集整理的這篇文章主要介紹了
(十)搭建springboot商城--商品热销排行
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1創建數據庫
2.創建實體類Product
public class Product extends BaseEntity implements Serializable {private Integer id;private Integer categoryId;private String itemType;private String title;private String sellPoint;private Long price;private Integer num;private String image;private Integer status;private Integer priority;3 創建持久層?
3.1規劃需要執行的SQL語句
select * from t_product where status=1 order by priority DESC LIMIT 0,4
3.2 接口與抽象方法
/*** 熱銷商品查詢* @return 前四的熱銷商品*/List<Product> findHotList();3.3 配置SQL映射
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace屬性:用于指定當前的映射文件和哪個接口進行映射,需要指定接口的文件路徑,需要標注包的完整路徑 --> <mapper namespace="com.cy.store.mapper.ProductMapper"><resultMap id="ProductEntityMap" type="com.cy.store.entity.Product"><id column="id" property="id"/><result column="category_id" property="categoryId"/><result column="item_type" property="itemType"/><result column="sell_point" property="sellPoint"/><result column="created_user" property="createdUser"></result><result column="created_time" property="createdTime"></result><result column="modified_user" property="modifiedUser"></result><result column="modified_time" property="modifiedTime"></result></resultMap><select id="findHotList" resultMap="ProductEntityMap">select * from t_product where status=1 order bypriority DESC limit 0,4</select> </mapper>4 業務層
4.1 規劃異常
無異常
4.2 接口與抽象方法
package com.cy.store.service;import com.cy.store.entity.Product;import java.util.List;public interface IProductService {List<Product> findHotList(); }4.3 實現抽象方法
package com.cy.store.service.impl;import com.cy.store.entity.Product; import com.cy.store.mapper.ProductMapper; import com.cy.store.service.IProductService; import org.springframework.beans.factory.annotation.Autowired;import java.util.List;public class IProductServiceImpl implements IProductService {@Autowiredprivate ProductMapper productMapper;@Overridepublic List<Product> findHotList() {List<Product> list = productMapper.findHotList();for (Product product : list) {product.setPriority(null);product.setCreatedUser(null);product.setCreatedTime(null);product.setModifiedTime(null);product.setModifiedUser(null);}return list;} }5. 控制器
5.1 處理異常
無異常
5.2 請求設計
/products/hot_list
get
JsonResult<Product>
加入白名單
5.3 處理請求?
package com.cy.store.controller;import com.cy.store.entity.Product; import com.cy.store.service.IProductService; import com.cy.store.util.JsonResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController @RequestMapping("products") public class ProductsController extends BaseController{@Autowiredprivate IProductService productService;@RequestMapping("hot_list")public JsonResult<List<Product>> getHostList(){List<Product> list = productService.findHotList();return new JsonResult<>(OK,list);}}6 前端頁面
總結
以上是生活随笔為你收集整理的(十)搭建springboot商城--商品热销排行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 虾皮马来西亚热销产品有哪些?
- 下一篇: Arduino与Proteus仿真实例-