小说项目练习#2管理端系统(1)

这篇没什么营养价值,不用往下看了。

今天懒得动脑先贴一下代码高兴了再细写日志

controller文件夹

package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Novels;
import com.ruoyi.system.service.INovelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小说Controller
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
@RestController
@RequestMapping("/system/novels")
public class NovelsController extends BaseController
{
    @Autowired
    private INovelsService novelsService;

    /**
     * 查询小说列表
     */
    @PreAuthorize("@ss.hasPermi('system:novels:list')")
    @GetMapping("/list")
    public TableDataInfo list(Novels novels)
    {
        startPage();
        List<Novels> list = novelsService.selectNovelsList(novels);
        return getDataTable(list);
    }

    /**
     * 导出小说列表
     */
    @PreAuthorize("@ss.hasPermi('system:novels:export')")
    @Log(title = "小说", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Novels novels)
    {
        List<Novels> list = novelsService.selectNovelsList(novels);
        ExcelUtil<Novels> util = new ExcelUtil<Novels>(Novels.class);
        util.exportExcel(response, list, "小说数据");
    }

    /**
     * 获取小说详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:novels:query')")
    @GetMapping(value = "/{novelsId}")
    public AjaxResult getInfo(@PathVariable("novelsId") Long novelsId)
    {
        return success(novelsService.selectNovelsByNovelsId(novelsId));
    }

    /**
     * 新增小说
     */
    @PreAuthorize("@ss.hasPermi('system:novels:add')")
    @Log(title = "小说", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Novels novels)
    {
        return toAjax(novelsService.insertNovels(novels));
    }

    /**
     * 修改小说
     */
    @PreAuthorize("@ss.hasPermi('system:novels:edit')")
    @Log(title = "小说", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Novels novels)
    {
        return toAjax(novelsService.updateNovels(novels));
    }

    /**
     * 删除小说
     */
    @PreAuthorize("@ss.hasPermi('system:novels:remove')")
    @Log(title = "小说", businessType = BusinessType.DELETE)
	@DeleteMapping("/{novelsIds}")
    public AjaxResult remove(@PathVariable Long[] novelsIds)
    {
        return toAjax(novelsService.deleteNovelsByNovelsIds(novelsIds));
    }
}

domain文件夹

package com.ruoyi.system.domain;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 小说对象 novels
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
public class Novels extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 小说id */
    private Long novelsId;

    /** 小说标题 */
    @Excel(name = "小说标题")
    private String novelsTitle;

    /** 作家id */
    @Excel(name = "作家id")
    private Long writersId;

    /** 小说封面 */
    @Excel(name = "小说封面")
    private String novelsCover;

    /** 小说简介 */
    @Excel(name = "小说简介")
    private String novelsSynopsis;

    /** 小说更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "小说更新时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date novelsUpdate;

    /** 小说发布时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "小说发布时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date novelsPublish;

    /** 小说总字数 */
    @Excel(name = "小说总字数")
    private Long novelsWord;

    /** 小说总章节数 */
    @Excel(name = "小说总章节数")
    private Long novelsChapter;

    /** 小说阅读量 */
    @Excel(name = "小说阅读量")
    private Long novelsRead;

    /** 小说点赞量 */
    @Excel(name = "小说点赞量")
    private Long novelsLike;

    /** 小说评论数 */
    @Excel(name = "小说评论数")
    private Long novelsComment;

    public void setNovelsId(Long novelsId) 
    {
        this.novelsId = novelsId;
    }

    public Long getNovelsId() 
    {
        return novelsId;
    }
    public void setNovelsTitle(String novelsTitle) 
    {
        this.novelsTitle = novelsTitle;
    }

    public String getNovelsTitle() 
    {
        return novelsTitle;
    }
    public void setWritersId(Long writersId) 
    {
        this.writersId = writersId;
    }

    public Long getWritersId() 
    {
        return writersId;
    }
    public void setNovelsCover(String novelsCover) 
    {
        this.novelsCover = novelsCover;
    }

    public String getNovelsCover() 
    {
        return novelsCover;
    }
    public void setNovelsSynopsis(String novelsSynopsis) 
    {
        this.novelsSynopsis = novelsSynopsis;
    }

    public String getNovelsSynopsis() 
    {
        return novelsSynopsis;
    }
    public void setNovelsUpdate(Date novelsUpdate) 
    {
        this.novelsUpdate = novelsUpdate;
    }

    public Date getNovelsUpdate() 
    {
        return novelsUpdate;
    }
    public void setNovelsPublish(Date novelsPublish) 
    {
        this.novelsPublish = novelsPublish;
    }

    public Date getNovelsPublish() 
    {
        return novelsPublish;
    }
    public void setNovelsWord(Long novelsWord) 
    {
        this.novelsWord = novelsWord;
    }

    public Long getNovelsWord() 
    {
        return novelsWord;
    }
    public void setNovelsChapter(Long novelsChapter) 
    {
        this.novelsChapter = novelsChapter;
    }

    public Long getNovelsChapter() 
    {
        return novelsChapter;
    }
    public void setNovelsRead(Long novelsRead) 
    {
        this.novelsRead = novelsRead;
    }

    public Long getNovelsRead() 
    {
        return novelsRead;
    }
    public void setNovelsLike(Long novelsLike) 
    {
        this.novelsLike = novelsLike;
    }

    public Long getNovelsLike() 
    {
        return novelsLike;
    }
    public void setNovelsComment(Long novelsComment) 
    {
        this.novelsComment = novelsComment;
    }

    public Long getNovelsComment() 
    {
        return novelsComment;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("novelsId", getNovelsId())
            .append("novelsTitle", getNovelsTitle())
            .append("writersId", getWritersId())
            .append("novelsCover", getNovelsCover())
            .append("novelsSynopsis", getNovelsSynopsis())
            .append("novelsUpdate", getNovelsUpdate())
            .append("novelsPublish", getNovelsPublish())
            .append("novelsWord", getNovelsWord())
            .append("novelsChapter", getNovelsChapter())
            .append("novelsRead", getNovelsRead())
            .append("novelsLike", getNovelsLike())
            .append("novelsComment", getNovelsComment())
            .toString();
    }
}

mapper文件夹

package com.ruoyi.system.mapper;

import java.util.List;
import com.ruoyi.system.domain.Novels;

/**
 * 小说Mapper接口
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
public interface NovelsMapper 
{
    /**
     * 查询小说
     * 
     * @param novelsId 小说主键
     * @return 小说
     */
    public Novels selectNovelsByNovelsId(Long novelsId);

    /**
     * 查询小说列表
     * 
     * @param novels 小说
     * @return 小说集合
     */
    public List<Novels> selectNovelsList(Novels novels);

    /**
     * 新增小说
     * 
     * @param novels 小说
     * @return 结果
     */
    public int insertNovels(Novels novels);

    /**
     * 修改小说
     * 
     * @param novels 小说
     * @return 结果
     */
    public int updateNovels(Novels novels);

    /**
     * 删除小说
     * 
     * @param novelsId 小说主键
     * @return 结果
     */
    public int deleteNovelsByNovelsId(Long novelsId);

    /**
     * 批量删除小说
     * 
     * @param novelsIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteNovelsByNovelsIds(Long[] novelsIds);
}

service文件夹

package com.ruoyi.system.service;

import java.util.List;
import com.ruoyi.system.domain.Novels;

/**
 * 小说Service接口
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
public interface INovelsService 
{
    /**
     * 查询小说
     * 
     * @param novelsId 小说主键
     * @return 小说
     */
    public Novels selectNovelsByNovelsId(Long novelsId);

    /**
     * 查询小说列表
     * 
     * @param novels 小说
     * @return 小说集合
     */
    public List<Novels> selectNovelsList(Novels novels);

    /**
     * 新增小说
     * 
     * @param novels 小说
     * @return 结果
     */
    public int insertNovels(Novels novels);

    /**
     * 修改小说
     * 
     * @param novels 小说
     * @return 结果
     */
    public int updateNovels(Novels novels);

    /**
     * 批量删除小说
     * 
     * @param novelsIds 需要删除的小说主键集合
     * @return 结果
     */
    public int deleteNovelsByNovelsIds(Long[] novelsIds);

    /**
     * 删除小说信息
     * 
     * @param novelsId 小说主键
     * @return 结果
     */
    public int deleteNovelsByNovelsId(Long novelsId);
}

service.impl文件夹

package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.NovelsMapper;
import com.ruoyi.system.domain.Novels;
import com.ruoyi.system.service.INovelsService;

/**
 * 小说Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-21
 */
@Service
public class NovelsServiceImpl implements INovelsService 
{
    @Autowired
    private NovelsMapper novelsMapper;

    /**
     * 查询小说
     * 
     * @param novelsId 小说主键
     * @return 小说
     */
    @Override
    public Novels selectNovelsByNovelsId(Long novelsId)
    {
        return novelsMapper.selectNovelsByNovelsId(novelsId);
    }

    /**
     * 查询小说列表
     * 
     * @param novels 小说
     * @return 小说
     */
    @Override
    public List<Novels> selectNovelsList(Novels novels)
    {
        return novelsMapper.selectNovelsList(novels);
    }

    /**
     * 新增小说
     * 
     * @param novels 小说
     * @return 结果
     */
    @Override
    public int insertNovels(Novels novels)
    {
        return novelsMapper.insertNovels(novels);
    }

    /**
     * 修改小说
     * 
     * @param novels 小说
     * @return 结果
     */
    @Override
    public int updateNovels(Novels novels)
    {
        return novelsMapper.updateNovels(novels);
    }

    /**
     * 批量删除小说
     * 
     * @param novelsIds 需要删除的小说主键
     * @return 结果
     */
    @Override
    public int deleteNovelsByNovelsIds(Long[] novelsIds)
    {
        return novelsMapper.deleteNovelsByNovelsIds(novelsIds);
    }

    /**
     * 删除小说信息
     * 
     * @param novelsId 小说主键
     * @return 结果
     */
    @Override
    public int deleteNovelsByNovelsId(Long novelsId)
    {
        return novelsMapper.deleteNovelsByNovelsId(novelsId);
    }
}

mapper文件夹

<?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.ruoyi.system.mapper.NovelsMapper">
    
    <resultMap type="Novels" id="NovelsResult">
        <result property="novelsId"    column="novels_id"    />
        <result property="novelsTitle"    column="novels_title"    />
        <result property="writersId"    column="writers_id"    />
        <result property="novelsCover"    column="novels_cover"    />
        <result property="novelsSynopsis"    column="novels_synopsis"    />
        <result property="novelsUpdate"    column="novels_update"    />
        <result property="novelsPublish"    column="novels_publish"    />
        <result property="novelsWord"    column="novels_word"    />
        <result property="novelsChapter"    column="novels_chapter"    />
        <result property="novelsRead"    column="novels_read"    />
        <result property="novelsLike"    column="novels_like"    />
        <result property="novelsComment"    column="novels_comment"    />
    </resultMap>

    <sql id="selectNovelsVo">
        select novels_id, novels_title, writers_id, novels_cover, novels_synopsis, novels_update, novels_publish, novels_word, novels_chapter, novels_read, novels_like, novels_comment from novels
    </sql>

    <select id="selectNovelsList" parameterType="Novels" resultMap="NovelsResult">
        <include refid="selectNovelsVo"/>
        <where>  
            <if test="novelsTitle != null  and novelsTitle != ''"> and novels_title = #{novelsTitle}</if>
            <if test="writersId != null "> and writers_id = #{writersId}</if>
            <if test="novelsUpdate != null "> and novels_update = #{novelsUpdate}</if>
            <if test="novelsPublish != null "> and novels_publish = #{novelsPublish}</if>
        </where>
    </select>
    
    <select id="selectNovelsByNovelsId" parameterType="Long" resultMap="NovelsResult">
        <include refid="selectNovelsVo"/>
        where novels_id = #{novelsId}
    </select>

    <insert id="insertNovels" parameterType="Novels" useGeneratedKeys="true" keyProperty="novelsId">
        insert into novels
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="novelsTitle != null and novelsTitle != ''">novels_title,</if>
            <if test="writersId != null">writers_id,</if>
            <if test="novelsCover != null and novelsCover != ''">novels_cover,</if>
            <if test="novelsSynopsis != null and novelsSynopsis != ''">novels_synopsis,</if>
            <if test="novelsUpdate != null">novels_update,</if>
            <if test="novelsPublish != null">novels_publish,</if>
            <if test="novelsWord != null">novels_word,</if>
            <if test="novelsChapter != null">novels_chapter,</if>
            <if test="novelsRead != null">novels_read,</if>
            <if test="novelsLike != null">novels_like,</if>
            <if test="novelsComment != null">novels_comment,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="novelsTitle != null and novelsTitle != ''">#{novelsTitle},</if>
            <if test="writersId != null">#{writersId},</if>
            <if test="novelsCover != null and novelsCover != ''">#{novelsCover},</if>
            <if test="novelsSynopsis != null and novelsSynopsis != ''">#{novelsSynopsis},</if>
            <if test="novelsUpdate != null">#{novelsUpdate},</if>
            <if test="novelsPublish != null">#{novelsPublish},</if>
            <if test="novelsWord != null">#{novelsWord},</if>
            <if test="novelsChapter != null">#{novelsChapter},</if>
            <if test="novelsRead != null">#{novelsRead},</if>
            <if test="novelsLike != null">#{novelsLike},</if>
            <if test="novelsComment != null">#{novelsComment},</if>
         </trim>
    </insert>

    <update id="updateNovels" parameterType="Novels">
        update novels
        <trim prefix="SET" suffixOverrides=",">
            <if test="novelsTitle != null and novelsTitle != ''">novels_title = #{novelsTitle},</if>
            <if test="writersId != null">writers_id = #{writersId},</if>
            <if test="novelsCover != null and novelsCover != ''">novels_cover = #{novelsCover},</if>
            <if test="novelsSynopsis != null and novelsSynopsis != ''">novels_synopsis = #{novelsSynopsis},</if>
            <if test="novelsUpdate != null">novels_update = #{novelsUpdate},</if>
            <if test="novelsPublish != null">novels_publish = #{novelsPublish},</if>
            <if test="novelsWord != null">novels_word = #{novelsWord},</if>
            <if test="novelsChapter != null">novels_chapter = #{novelsChapter},</if>
            <if test="novelsRead != null">novels_read = #{novelsRead},</if>
            <if test="novelsLike != null">novels_like = #{novelsLike},</if>
            <if test="novelsComment != null">novels_comment = #{novelsComment},</if>
        </trim>
        where novels_id = #{novelsId}
    </update>

    <delete id="deleteNovelsByNovelsId" parameterType="Long">
        delete from novels where novels_id = #{novelsId}
    </delete>

    <delete id="deleteNovelsByNovelsIds" parameterType="String">
        delete from novels where novels_id in 
        <foreach item="novelsId" collection="array" open="(" separator="," close=")">
            #{novelsId}
        </foreach>
    </delete>
</mapper>

剩下的懒得贴了今天就这样吧懒死我了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值