增加分类字段

1 个父辈 c848589d
......@@ -36,18 +36,20 @@ public class ArticlesController extends BaseController {
@ResponseBody
public Object getArticlesList(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
@RequestParam(value = "size", defaultValue = "10", required = false) Integer size,
@RequestParam(value = "keyword", required = false) String keyword) {
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "type", required = false) Integer type) {
return new Vo_msg(0, articleService.getArticlesList(page, size, keyword));
return new Vo_msg(0, articleService.getArticlesList(page, size, keyword,type));
}
// 添加
@RequestMapping(value = "/addArticle", method = RequestMethod.POST)
@ResponseBody
public Object addArticle(@RequestParam(value = "title", required = true) String title,
@RequestParam(value = "content", required = true) String content,
@RequestParam(value = "imgurl", required = false) String imgurl) {
String result = articleService.addArticle(title, content, imgurl);
@RequestParam(value = "content", required = false) String content,
@RequestParam(value = "imgurl", required = false) String imgurl,
@RequestParam(value = "type", required = false) Integer type) {
String result = articleService.addArticle(title, content, imgurl,type);
if (result.equals("ok")) {
return new Vo_msg(0, null, "添加成功");
} else {
......@@ -58,8 +60,9 @@ public class ArticlesController extends BaseController {
// 修改
@RequestMapping(value = "/updateArticle", method = RequestMethod.POST)
@ResponseBody
public Object updateArticle(Integer id, String title, String content, String imgurl) {
String result = articleService.updateArticle(id, title, content, imgurl);
public Object updateArticle(Integer id, String title, String content, String imgurl,
@RequestParam(value = "type", required = false) Integer type) {
String result = articleService.updateArticle(id, title, content, imgurl,type);
if (result.equals("ok")) {
return new Vo_msg(0, "修改成功");
} else {
......
......@@ -158,7 +158,7 @@ public class WxMiniController extends BaseController {
@ResponseBody
public Object getArticlesList(Integer page, Integer pagesize) {
return new Vo_msg(0, articleService.getArticlesList(page, pagesize, ""));
return new Vo_msg(0, articleService.getArticlesList(page, pagesize, "",null));
}
// 增加文章浏览数
......
......@@ -5,228 +5,182 @@ import java.util.Date;
import javax.persistence.Id;
public class Articles {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.id
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
@Id
private Integer id;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.title
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private String title;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.imgurl
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private String imgurl;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.createdtime
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private Date createdtime;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.viewcount
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private Integer viewcount;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.deleted
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private Boolean deleted;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column articles.content
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
private String content;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.id
*
* @return the value of articles.id
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.id
*
* @param id the value for articles.id
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.title
*
* @return the value of articles.title
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getTitle() {
return title;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.title
*
* @param title the value for articles.title
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.imgurl
*
* @return the value of articles.imgurl
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getImgurl() {
return imgurl;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.imgurl
*
* @param imgurl the value for articles.imgurl
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setImgurl(String imgurl) {
this.imgurl = imgurl == null ? null : imgurl.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.createdtime
*
* @return the value of articles.createdtime
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Date getCreatedtime() {
return createdtime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.createdtime
*
* @param createdtime the value for articles.createdtime
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setCreatedtime(Date createdtime) {
this.createdtime = createdtime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.viewcount
*
* @return the value of articles.viewcount
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Integer getViewcount() {
return viewcount;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.viewcount
*
* @param viewcount the value for articles.viewcount
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setViewcount(Integer viewcount) {
this.viewcount = viewcount;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.deleted
*
* @return the value of articles.deleted
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Boolean getDeleted() {
return deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.deleted
*
* @param deleted the value for articles.deleted
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column articles.content
*
* @return the value of articles.content
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getContent() {
return content;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column articles.content
*
* @param content the value for articles.content
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
@Id
private Integer id;
private String title;
private String imgurl;
private Date createdtime;
private Integer viewcount;
private Boolean deleted;
private Integer type;
private String content;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.title
*
* @return the value of articles.title
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getTitle() {
return title;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.title
*
* @param title
* the value for articles.title
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.imgurl
*
* @return the value of articles.imgurl
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getImgurl() {
return imgurl;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.imgurl
*
* @param imgurl
* the value for articles.imgurl
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setImgurl(String imgurl) {
this.imgurl = imgurl == null ? null : imgurl.trim();
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.createdtime
*
* @return the value of articles.createdtime
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Date getCreatedtime() {
return createdtime;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.createdtime
*
* @param createdtime
* the value for articles.createdtime
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setCreatedtime(Date createdtime) {
this.createdtime = createdtime;
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.viewcount
*
* @return the value of articles.viewcount
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Integer getViewcount() {
return viewcount;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.viewcount
*
* @param viewcount
* the value for articles.viewcount
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setViewcount(Integer viewcount) {
this.viewcount = viewcount;
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.deleted
*
* @return the value of articles.deleted
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public Boolean getDeleted() {
return deleted;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.deleted
*
* @param deleted
* the value for articles.deleted
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}
/**
* This method was generated by MyBatis Generator. This method returns the value
* of the database column articles.content
*
* @return the value of articles.content
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public String getContent() {
return content;
}
/**
* This method was generated by MyBatis Generator. This method sets the value of
* the database column articles.content
*
* @param content
* the value for articles.content
*
* @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
......@@ -57,7 +57,7 @@ public class ArticleService{
@Autowired
ArticlesDao articleDao;
public PageResults<Articles> getArticlesList(Integer page, Integer pagesize, String keyword) {
public PageResults<Articles> getArticlesList(Integer page, Integer pagesize, String keyword,Integer type) {
if(StringUtil.isZearoOrNull(pagesize))pagesize=10;
Example example = new Example(Articles.class);
example.createCriteria().andEqualTo("deleted", false);
......@@ -65,6 +65,9 @@ public class ArticleService{
if(!Strings.isNullOrEmpty(keyword)){
example.createCriteria().andLike("title", "%"+keyword+"%");
}
if(type!=null && type>0) {
example.createCriteria().andEqualTo("type",type);
}
example.setOrderByClause(" id desc ");
List<Articles> list = articleDao.selectByExampleAndRowBounds(example, row);
int total = articleDao.selectCountByExample(example);
......@@ -76,7 +79,7 @@ public class ArticleService{
return pageresult;
}
public String addArticle(String title, String content, String imgurl) {
public String addArticle(String title, String content, String imgurl,Integer type) {
// TODO Auto-generated method stub
Articles article=new Articles();
article.setTitle(title);
......@@ -85,22 +88,19 @@ public class ArticleService{
article.setCreatedtime(CommonUtil.getTime());
article.setDeleted(false);
article.setViewcount(0);
article.setType(type);
int row = articleDao.insertSelective(article);
return row > 0 ? "ok" : "添加失败,数据异常";
}
/* (非 Javadoc)
* Description:
* @see com.w1hd.zzhnc.service.ArticleService#updateArticle(java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
*/
public String updateArticle(Integer id, String title, String content, String imgurl) {
public String updateArticle(Integer id, String title, String content, String imgurl,Integer type) {
// TODO Auto-generated method stub
Articles article=articleDao.selectByPrimaryKey(id);
if(article==null)return "修改失败,数据不存在";
article.setTitle(title);
article.setContent(content);
article.setImgurl(imgurl);
article.setType(type);
int row = articleDao.updateByPrimaryKeySelective(article);
return row > 0 ? "ok" : "修改失败,数据异常";
}
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!