Swiper轮播图后端接口实现

bash 复制代码
mybatis-plus:
  global-config:
    db-config:
      id-type: auto #id生成规则:数据库id自增
  configuration:
    map-underscore-to-camel-case: false  # 开启驼峰功能
    auto-mapping-behavior: full # 自动映射任何复杂的结果
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mybatis/mapper/*.xml

产品表

bash 复制代码
/*
SQLyog Ultimate v11.33 (64 bit)
MySQL - 5.7.18-log 
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `t_product` (
	`id` int (11),
	`name` varchar (300),
	`price` Decimal (10),
	`stock` int (11),
	`proPic` varchar (765),
	`isHot` bit (1),
	`isSwiper` bit (1),
	`swiperPic` varchar (765),
	`swiperSort` int (11),
	`typeId` int (11),
	`hotDateTime` datetime ,
	`productIntroImgs` varchar (6000),
	`productParaImgs` varchar (6000),
	`description` varchar (6000)
); 
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('1','小米电视大师 82英寸','10999.00','3451','21.png','','','2.jpg','3','14','2021-11-26 21:36:34','\"\"','\"\"','\"\"');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('4','Xiaomi 11','3799.00','3232','6.png','','','default.jpg','0','2','2021-07-28 21:36:34','<img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/11.jpg\'></img>','<img width=\'100%\' src=\'http://192.168.0.116/image/productParaImgs/11.jpg\'></img>','「全版本领券立减200元,券后价3299元起;享至高24期免息;赠手机保护壳*1;【全款支付套装】赠果冻包」');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('5','Redmi K40 游戏增强版','2299.00','2005','11.png','','','1.jpg','1','39',NULL,'\"\"','\"\"','\"\"');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('6','Xiaomi 11 Pro','4499.00','2343','1.png','','','default.jpg','0','2','2021-09-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('7','Xiaomi MIX FOLD折叠屏手机','7999.00','2222','2.png','','','default.jpg','0','3','2021-10-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('8','Note 9 5G','1199.00','1111','3.png','','','default.jpg','0','40','2021-09-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('9','Xiaomi 10S','2999.00','1111','4.png','','','default.jpg','0','2','2021-12-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('10','Note 9 Pro 5G','1399.00','2222','5.png','','','default.jpg','0','40','2021-11-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('11','黑鲨4','2499.00','3322','7.png','','','default.jpg','0','41','2021-11-28 21:36:34','\"\"',NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('12','Redmi  K40 Pro 系列','2499.00','3244','8.png','','','default.jpg','0','39','2021-11-28 21:36:34',NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('14','Xiaomi Civi','2599.00','4444','9.png','','','default.jpg','0','1',NULL,'<img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/1.jpg\'></img><img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/2.jpg\'></img><img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/3.jpg\'></img>','<img width=\'100%\' src=\'http://192.168.0.116/image/productParaImgs/1.jpg\'></img><img width=\'100%\' src=\'http://192.168.0.116/image/productParaImgs/2.jpg\'></img>','「购机至高享24期免息;赠Redmi AirDots 2真无线蓝牙耳机;赠Keep会员7天体验卡;+110元得Air2 SE蓝牙耳机」');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('15','Xiaomi 11 Ultra','5499.00','4444','10.png','','','default.jpg','0','2',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('16','小米平板5','1999.00','444','13.png','','','default.jpg','0','5',NULL,'<img src=\'http://192.168.0.116/image/productIntroImgs/111.jpg\'></img><img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/222.jpg\'></img><img width=\'100%\' src=\'http://192.168.0.116/image/productIntroImgs/333.jpg\'></img>','<img width=\'100%\' src=\'http://192.168.0.116/image/productParaImgs/111.jpg\'></img>','11英寸大屏 2.5K超清显示 120Hz高刷新率');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('17','小米平板5 Pro','2499.00','444','14.png','','','default.jpg','0','5',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('19','RedmiBook Pro 15 增强版','5299.00','444','15.png','','','default.jpg','0','6',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('20','Redmi G 2021','6499.00','1999','16.png','','','3.jpg','2','6',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('21','Redmi G 2021 锐龙版','7499.00','2000','17.png','','','default.jpg','0','6',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('22','RedmiBook Pro 14 增强版','4999.00','777','18.png','','','default.jpg','0','6',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('23','小米笔记本 Pro 14 锐龙版','5499.00','666','19.png','','','default.jpg','0','7',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('24','小米笔记本 Pro 14 增强版','5499.00','666','20.png','','','default.jpg','0','7',NULL,NULL,NULL,NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('26','1','1.00','1','default.jpg','','','default.jpg','0','6',NULL,'1','1',NULL);
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('27','1','2.00','3','default.jpg','','','default.jpg','0','6',NULL,'5','6','4');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('28','2','3.00','4','default.jpg','','','default.jpg','0','6',NULL,'6','7','5');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('29','1','1.00','1','default.jpg','','','default.jpg','0','11',NULL,'1','1','1');
insert into `t_product` (`id`, `name`, `price`, `stock`, `proPic`, `isHot`, `isSwiper`, `swiperPic`, `swiperSort`, `typeId`, `hotDateTime`, `productIntroImgs`, `productParaImgs`, `description`) values('30','223335552','322.00','22355','default.jpg','','','default.jpg','0','6',NULL,'22333522','22333544442','22333511');
bash 复制代码
package com.java1234.entity;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 商品
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2021-11-22 22:13
 */
@TableName("t_product")
@Data
public class Product {

    private Integer id; // 编号

    private String name; // 名称

    private BigDecimal price; // 价格

    private String productIntroImgs; // 商品介绍图片

    private String productParaImgs;  // 商品规格参数图片

    private Integer stock; // 库存

    private String proPic="default.jpg"; // 商品图片

    private boolean isHot=false; // 是否热门推荐商品

    private boolean isSwiper=false; // 是否轮播图片商品

    private Integer swiperSort=0; // 轮播排序

    private String swiperPic="default.jpg"; // 商品轮播图片

    private String description; // 描述

    @JsonSerialize(using=CustomDateTimeSerializer.class)
    private Date hotDateTime; // 设置热门推荐日期时间



}
bash 复制代码
package com.java1234.entity;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * 自定义返回JSON 数据格式中日期格式化处理
 * @author java1234 小锋 老师
 *
 */
public class CustomDateTimeSerializer extends JsonSerializer<Date>{

	@Override
	public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers)
			throws IOException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
		gen.writeString(sdf.format(value));  
	}

}
bash 复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java1234.mapper.ProductMapper">


</mapper>
bash 复制代码
package com.java1234.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java1234.entity.Product;

public interface ProductMapper extends BaseMapper<Product> {
}
bash 复制代码
package com.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.java1234.entity.Product;
import com.java1234.mapper.ProductMapper;
import com.java1234.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * 商品Service实现类
 */
@Service("productService")
public class IProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;
}
bash 复制代码
package com.java1234.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.java1234.entity.Product;

/**
 * 商品Service接口
 */
public interface IProductService extends IService<Product> {
}
bash 复制代码
package com.java1234.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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);
    }
}
相关推荐
m0_5719575831 分钟前
Java | Leetcode Java题解之第543题二叉树的直径
java·leetcode·题解
魔道不误砍柴功3 小时前
Java 中如何巧妙应用 Function 让方法复用性更强
java·开发语言·python
NiNg_1_2343 小时前
SpringBoot整合SpringSecurity实现密码加密解密、登录认证退出功能
java·spring boot·后端
闲晨3 小时前
C++ 继承:代码传承的魔法棒,开启奇幻编程之旅
java·c语言·开发语言·c++·经验分享
测开小菜鸟4 小时前
使用python向钉钉群聊发送消息
java·python·钉钉
P.H. Infinity5 小时前
【RabbitMQ】04-发送者可靠性
java·rabbitmq·java-rabbitmq
生命几十年3万天5 小时前
java的threadlocal为何内存泄漏
java
caridle5 小时前
教程:使用 InterBase Express 访问数据库(五):TIBTransaction
java·数据库·express
^velpro^5 小时前
数据库连接池的创建
java·开发语言·数据库
苹果醋36 小时前
Java8->Java19的初步探索
java·运维·spring boot·mysql·nginx