月木学途开发 5.轮播图模块

概述

效果图

月木学途开发 5.轮播图模块_第1张图片

月木学途开发 5.轮播图模块_第2张图片 

数据库设计

轮播图表
DROP TABLE IF EXISTS `banner`;
CREATE TABLE `banner` (
  `bannerId` int(11) NOT NULL AUTO_INCREMENT,
  `bannerUrl` longtext,
  `bannerDesc` varchar(255) DEFAULT NULL,
  `bannerTypeId` int(11) DEFAULT NULL,
  PRIMARY KEY (`bannerId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;

轮播图类型表
DROP TABLE IF EXISTS `banner_type`;
CREATE TABLE `banner_type` (
  `bannerTypeId` int(11) NOT NULL AUTO_INCREMENT,
  `bannerTypeName` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`bannerTypeId`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;

实体类设计

轮播图
package jkw.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;

/**
 * 轮播图
 */
@Data
public class Banner implements Serializable {
    @TableId
    private Integer bannerId;
    private String bannerUrl;//图片
    private String bannerDesc;//描述

    private Integer bannerTypeId;//类型
    @TableField(exist = false)
    private BannerType bannerType;
}

轮播图类型
package jkw.pojo;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;

/**
 * 轮播图类型
 */
@Data
public class BannerType implements Serializable {
    @TableId
    private Integer bannerTypeId;
    private String bannerTypeName;//类型名
}

Mapper层开发

BannerTypeMapper
package jkw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jkw.pojo.BannerType;

public interface BannerTypeMapper extends BaseMapper {
}

BannerMapper
package jkw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jkw.pojo.Banner;

public interface BannerMapper extends BaseMapper {
}

Service层开发

BannerTypeService
package jkw.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.BannerType;

import java.util.List;

public interface BannerTypeService {
    void add(BannerType BannerType);

    void update(BannerType BannerType);

    void delete(Integer id);

    BannerType findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);
}

BannerTypeServiceImpl
package jkw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.mapper.BannerTypeMapper;
import jkw.pojo.BannerType;
import jkw.service.BannerTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BannerTypeServiceImpl implements BannerTypeService {
    @Autowired
    private BannerTypeMapper bannerTypeMapper;

    @Override
    public void add(BannerType BannerType) {
        bannerTypeMapper.insert(BannerType);
    }

    @Override
    public void update(BannerType BannerType) {
        bannerTypeMapper.updateById(BannerType);
    }

    @Override
    public void delete(Integer id) {
        bannerTypeMapper.deleteById(id);
    }

    @Override
    public BannerType findById(Integer id) {
        return bannerTypeMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return bannerTypeMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return bannerTypeMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

BannerService
package jkw.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.Banner;

import java.util.List;

public interface BannerService {
    void add(Banner Banner);

    void update(Banner Banner);

    void delete(Integer id);

    Banner findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);
}

BannerServiceImpl
package jkw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.mapper.BannerMapper;
import jkw.pojo.Banner;
import jkw.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    @Override
    public void add(Banner Banner) {
        bannerMapper.insert(Banner);
    }

    @Override
    public void update(Banner Banner) {
        bannerMapper.updateById(Banner);
    }

    @Override
    public void delete(Integer id) {
        bannerMapper.deleteById(id);
    }

    @Override
    public Banner findById(Integer id) {
        return bannerMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return bannerMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return bannerMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

控制层开发

BannerTypeCon
package jkw.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.BannerType;
import jkw.service.BannerTypeService;
import jkw.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/back/bannerType")
public class BannerTypeCon {
    @Autowired
    private BannerTypeService bannerTypeService;

    /**
     * 新增
     *
     * @param bannerType
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult add(BannerType bannerType) {
        bannerTypeService.add(bannerType);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param bannerType
     * @return
     */
    @PostMapping("/update")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult update(BannerType bannerType) {
        bannerTypeService.update(bannerType);
        return BaseResult.ok();
    }

    /**
     * 删除
     *
     * @param bannerTypeId
     * @return
     */
    @DeleteMapping("/delete")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult delete(Integer bannerTypeId) {
        bannerTypeService.delete(bannerTypeId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询
     *
     * @param bannerTypeId
     * @return
     */
    @GetMapping("/findById")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult findById(Integer bannerTypeId) {
        BannerType bannerType = bannerTypeService.findById(bannerTypeId);
        return BaseResult.ok(bannerType);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult findAll() {
        List all = bannerTypeService.findAll();
        return BaseResult.ok(all);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult search(String search, int page, int size) {
        Page brandPage = bannerTypeService.search(search, page, size);
        return BaseResult.ok(brandPage);
    }
}

BannerCon
package jkw.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.Banner;
import jkw.service.BannerService;
import jkw.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/back/banner")
@CrossOrigin
@RestController
public class BannerCon {
    @Autowired
    private BannerService bannerService;

    /**
     * 新增
     *
     * @param banner
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult add(Banner banner) {
        bannerService.add(banner);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param banner
     * @return
     */
    @PostMapping("/update")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult update(Banner banner) {
        bannerService.update(banner);
        return BaseResult.ok();
    }

    /**
     * 删除
     *
     * @param bannerId
     * @return
     */
    @DeleteMapping("/delete")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult delete(Integer bannerId) {
        bannerService.delete(bannerId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询
     *
     * @param bannerId
     * @return
     */
    @GetMapping("/findById")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult findById(Integer bannerId) {
        Banner banner = bannerService.findById(bannerId);
        return BaseResult.ok(banner);
    }

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/findAll")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult findAll() {
        List all = bannerService.findAll();
        return BaseResult.ok(all);
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search")
    @PreAuthorize("hasAnyAuthority('/website/banner')")
    public BaseResult search(String search, int page, int size) {
        Page brandPage = bannerService.search(search, page, size);
        return BaseResult.ok(brandPage);
    }
}

后台ui设计

BannerType.vue



Banner.vue



你可能感兴趣的:(月木学途项目开发,spring)