
CREATE TABLE
tb_article
(id
varchar(255) NOT NULL COMMENT 'ID 主键',columnid
varchar(255) DEFAULT NULL COMMENT '专栏id',userid
varchar(255) NOT NULL COMMENT '用户id',title
varchar(255) NOT NULL COMMENT '标题',content
text NOT NULL COMMENT '内容',image
varchar(255) DEFAULT NULL COMMENT '文章封面',createtime
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '发布日期',modifytime
datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,ispublic
varchar(255) DEFAULT NULL COMMENT '是否公开 0 不公开 1 公开',istop
varchar(255) DEFAULT NULL COMMENT '是否置顶 0 不置顶 1 置顶',visits
bigint(20) DEFAULT NULL COMMENT '浏览量',thumbup
bigint(20) DEFAULT NULL COMMENT '点赞数',comment
bigint(20) DEFAULT NULL COMMENT '评论数',state
varchar(255) DEFAULT NULL COMMENT '0 未审核 1 已审核',channelid
int(11) DEFAULT NULL COMMENT '所属频道 关联频道表id ',url
varchar(255) DEFAULT NULL COMMENT 'url地址',type
varchar(255) DEFAULT NULL COMMENT '0 分享 1 专栏 ',PRIMARY KEY (
id
)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我们同样适用代码生成器
在文章dao 里面加入两个方法一个是 更新 文章审核 另外一个是 点赞
/**
* 加入审核
*/
@Modifying
@Query("update Article set state ='1' where id =?1")
public void examine(String id);
/**
* 点赞
*/
@Modifying
@Query("update Article set thumbup = thumbup +1 where id=?1")
public int updateThumbup(String id);
service层
public void examine(String id) {
articleDao.examine(id);
}
@Transactional
public int updateThumbup(String id) {
return articleDao.updateThumbup(id);
}
controller 层
@RequestMapping(value = "/examine/{id}", method = RequestMethod.PUT)
public Result examine(@PathVariable String id) {
articleService.examine(id);
return new Result(true, StatusCode.OK, "审核文章成功");
}
@RequestMapping(value = "/thumbup/{id}",method = RequestMethod.PUT)
public Result updateThumbup(@PathVariable String id) {
articleService.updateThumbup(id);
return new Result(true, StatusCode.OK, "点赞成功");
}
网友评论