springboot3+vue3脚手架搭建-06-系统公告模块的增删改查-系统公告前后台渲染

系统公告表

CREATE TABLE `notice` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '公告标题',
  `content` text COLLATE utf8mb4_unicode_ci COMMENT '公告内容',
  `time` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '发布时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='系统公告表';

Entity

public class Notice {
   
   
    private Integer id;
    private String title;
    private String content;
    private String time;

}

Mapper

public interface NoticeMapper {
   
   

    int insert(Notice notice);

    void updateById(Notice notice);

    void deleteById(Integer id);

    @Select("select * from `notice` where id = #{id}")
    Notice selectById(Integer id);

    List<Notice> selectAll(Notice notice);

}
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.NoticeMapper">

    <select id="selectAll" resultType="com.example.entity.Notice">
        select * from `notice`
        <where>
            <if test="title != null"> and title like concat('%', #{
   
   title}, '%')</if>
        </where>
    </select>

    <delete id="deleteById">
        delete from `notice`
        where id = #{
   
   id}
    </delete>

    <!-- insert into notice (username, password, ...) values ('notice', 'notice', ...) -->
    <insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
        insert into `notice`
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="time != null">time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{
   
   id},</if>
            <if test="title != null">#{
   
   title},</if>
            <if test="content != null">#{
   
   content},</if>
            <if test="time != null">#{
   
   time},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.Notice">
        update `notice`
        <set>
            <if test="title != null">
                title = #{
   
   title},
            </if>
            <if test="content != null">
                content = #{
   
   content},
            </if>
            <if test="time != null">
                time = #{
   
   time},
            </if>
        </set>
        where id = #{
   
   id}
    </update>

</mapper>

Service

@Service
public class NoticeService {
   
   

    @Resource
    private NoticeMapper noticeMapper;

    public void
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值