后端热门推荐商品接口实现

mybatis-plus分页配置

bash 复制代码
package com.java1234.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus配置类
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2022-01-30 8:10
 */
@Configuration
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }
}
bash 复制代码
package com.java1234.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/***
 *
 * web项目配置类
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:D:\\java1234-mall-v3\\swiperImgs\\");
        registry.addResourceHandler("/image/bigType/**").addResourceLocations("file:D:\\java1234-mall-v3\\bigTypeImgs\\");
        registry.addResourceHandler("/image/product/**").addResourceLocations("file:D:\\java1234-mall-v3\\productImgs\\");
    }
}
bash 复制代码
package com.java1234.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java1234.entity.Product;
import com.java1234.entity.R;
import com.java1234.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品Controller
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    /**
     * 查询轮播商品
     * @return
     */
    @GetMapping("/findSwiper")
    public R findSwiper(){
        List<Product> swiperProductList = productService.list(new QueryWrapper<Product>().eq("isSwiper", true).orderByAsc("swiperSort"));
        Map<String,Object> map=new HashMap<>();
        map.put("message",swiperProductList);
        return R.ok(map);
    }


    /**
     * 查询热门推荐商品8个
     * @return
     */
    @GetMapping("/findHot")
    public R findHot(){
        Page<Product> page=new Page<>(0,8);
        Page<Product> pageProduct= productService.page(page,new QueryWrapper<Product>().eq("isHot",true).orderByAsc("hotDateTime"));
        List<Product> hotProductList = pageProduct.getRecords();
        Map<String,Object> map=new HashMap<>();
        map.put("message",hotProductList);
        return R.ok(map);
    }
}
相关推荐
半青年12 分钟前
基于Qt开发的http/https客户端
java·c++·qt·网络协议·http·https·信息与通信
冠位巴萨辛山の翁26 分钟前
Maven
java·maven
Ten peaches1 小时前
苍穹外卖(用户下单、订单支付)
java·开发语言·spring boot
代码不停1 小时前
Java数据结构——Queue
java·开发语言·数据结构
MeteorSaraphines1 小时前
第 14 届蓝桥杯 C++ 青少组省赛中 / 高级组真题解析
java·算法
IT小鸟鸟2 小时前
LinkList 的底层数据结构及优缺点
java·数据结构·算法
咸鱼睡不醒_2 小时前
SpringBoot项目接入DeepSeek
java·spring boot·后端
ghostmen2 小时前
Java实现minio上传文件加解密操作
java·minio
刃神太酷啦2 小时前
C++入门(下)--《Hello C++ World!》(2)(C/C++)
java·c语言·c++·git·算法·github
努力的搬砖人.3 小时前
maven如何搭建自己的私服(windows版)?
java·windows·maven