月木学途开发 4.公告模块

概述

效果图

月木学途开发 4.公告模块_第1张图片

数据库设计

DROP TABLE IF EXISTS `announcement`;
CREATE TABLE `announcement` (
  `announcementId` int(11) NOT NULL AUTO_INCREMENT,
  `announcementTitle` varchar(255) DEFAULT NULL,
  `announcementTime` varchar(255) DEFAULT NULL,
  `announcementContent` longtext,
  PRIMARY KEY (`announcementId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;

实体类设计

/**
 * 公告
 */
@Data
public class Announcement implements Serializable {
    @TableId
    private Integer announcementId;
    private String announcementTitle;//标题
    private String announcementTime;//时间
    private String announcementContent;//内容
}

Mapper层开发

public interface AnnouncementMapper extends BaseMapper {
}

Service层开发

AnnouncementService
package jkw.service;

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

import java.util.List;

public interface AnnouncementService {
    void add(Announcement announcement);

    void update(Announcement announcement);

    void delete(Integer id);

    Announcement findById(Integer id);

    List findAll();

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

AnnouncementServiceImpl
package jkw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.mapper.AnnouncementMapper;
import jkw.pojo.Announcement;
import jkw.service.AnnouncementService;
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 AnnouncementServiceImpl implements AnnouncementService {
    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public void add(Announcement announcement) {
        announcementMapper.insert(announcement);
    }

    @Override
    public void update(Announcement announcement) {
        announcementMapper.updateById(announcement);
    }

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

    @Override
    public Announcement findById(Integer id) {
        return announcementMapper.selectById(id);
    }

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

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

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

}

控制层开发

AnnouncementCon
package jkw.controller.back;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jkw.pojo.Announcement;
import jkw.service.AnnouncementService;
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;

@RestController
@CrossOrigin
@RequestMapping("/back/announcement")
public class AnnouncementCon {

    @Autowired
    private AnnouncementService announcementService;

    /**
     * 新增
     *
     * @param announcement
     * @return
     */
    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('/website/announcement')")
    public BaseResult add(Announcement announcement) {
        announcementService.add(announcement);
        return BaseResult.ok();
    }

    /**
     * 修改
     *
     * @param announcement
     * @return
     */
    @PostMapping("/update")
    @PreAuthorize("hasAnyAuthority('/website/announcement')")
    public BaseResult update(Announcement announcement) {
        announcementService.update(announcement);
        return BaseResult.ok();
    }

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

    /**
     * 根据id查询
     *
     * @param announcementId
     * @return
     */
    @GetMapping("/findById")
    @PreAuthorize("hasAnyAuthority('/website/announcement')")
    public BaseResult findById(Integer announcementId) {
        Announcement announcement = announcementService.findById(announcementId);
        return BaseResult.ok(announcement);
    }

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

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

后台ui设计




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