如何在springboot中实现简单的草稿箱

73 阅读1分钟

如何在springboot中实现简单的草稿箱

建表

我们只需要给表加一个状态的字段来进行判断他是不是草稿即可
例如

CREATE TABLE `recipe` (
  `id` int NOT NULL AUTO_INCREMENT,
  `recipe_name` varchar(220) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `author` int NOT NULL,
  `time` varchar(220) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `recipe_picture` varchar(220) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `introduction` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `quick` int(1) unsigned zerofill DEFAULT '0',
  `difficulty` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `need_time` varchar(220) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `collectNums` int DEFAULT '0',
  `status` int DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=187 DEFAULT CHARSET=utf8mb3

sql语句

1.将内容填入表中并且指定状态

 <!--  存入草稿箱  -->
    <insert id="insertRecipeDraftfolder" parameterType="com.springboot2.pojo.Recipe">
        insert into recipe( recipe_name, author, time, recipe_picture, introduction
                          , difficulty, need_time, status)
        values (#{recipe_name}, #{author}, #{time}, #{recipe_picture}, #{introduction}, #{difficulty},
                #{need_time}, 3)
    </insert>

2.如果对草稿箱有改动

<update id="updateRecipeDraftfolder" parameterType="com.springboot2.pojo.Recipe">
        update recipe set recipe_name = #{recipe_name},
                          author = #{author},
                          time = #{time},
                          recipe_picture = #{recipe_picture},
                          introduction = #{introduction},
                          difficulty = #{difficulty},
                          need_time = #{need_time},
                          status = #{status}
    </update>

这时可以指定是保存还是上传草稿箱的内容

相关代码

1.dao层
在这里插入图片描述
2.service层
在这里插入图片描述
3.impl层
在这里插入图片描述
之后在controller层接收数据即可。