日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(十)搭建springboot商城--商品热销排行

發布時間:2024/3/12 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (十)搭建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商城--商品热销排行的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。