如何在springboot中实现简单的草稿箱
如何在springboot中实现简单的草稿箱
建表sql语句相关代码
建表
我们只需要给表加一个状态的字段来进行判断他是不是草稿即可 例如
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 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)
2.如果对草稿箱有改动
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}
这时可以指定是保存还是上传草稿箱的内容
相关代码
1.dao层 2.service层 3.impl层 之后在controller层接收数据即可。