(十)搭建springboot商城--商品热销排行
生活随笔
收集整理的這篇文章主要介紹了
(十)搭建springboot商城--商品热销排行
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1創(chuàng)建數(shù)據(jù)庫(kù)
2.創(chuàng)建實(shí)體類(lèi)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 創(chuàng)建持久層?
3.1規(guī)劃需要執(zhí)行的SQL語(yǔ)句
select * from t_product where status=1 order by priority DESC LIMIT 0,4
3.2 接口與抽象方法
/*** 熱銷(xiāo)商品查詢(xún)* @return 前四的熱銷(xiāo)商品*/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屬性:用于指定當(dāng)前的映射文件和哪個(gè)接口進(jìn)行映射,需要指定接口的文件路徑,需要標(biāo)注包的完整路徑 --> <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 業(yè)務(wù)層
4.1 規(guī)劃異常
無(wú)異常
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 實(shí)現(xiàn)抽象方法
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 處理異常
無(wú)異常
5.2 請(qǐng)求設(shè)計(jì)
/products/hot_list
get
JsonResult<Product>
加入白名單
5.3 處理請(qǐng)求?
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 前端頁(yè)面
總結(jié)
以上是生活随笔為你收集整理的(十)搭建springboot商城--商品热销排行的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 虾皮马来西亚热销产品有哪些?
- 下一篇: Arduino与Proteus仿真实例-