增加分类字段

1 个父辈 c848589d
...@@ -36,18 +36,20 @@ public class ArticlesController extends BaseController { ...@@ -36,18 +36,20 @@ public class ArticlesController extends BaseController {
@ResponseBody @ResponseBody
public Object getArticlesList(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page, public Object getArticlesList(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
@RequestParam(value = "size", defaultValue = "10", required = false) Integer size, @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) @RequestMapping(value = "/addArticle", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Object addArticle(@RequestParam(value = "title", required = true) String title, public Object addArticle(@RequestParam(value = "title", required = true) String title,
@RequestParam(value = "content", required = true) String content, @RequestParam(value = "content", required = false) String content,
@RequestParam(value = "imgurl", required = false) String imgurl) { @RequestParam(value = "imgurl", required = false) String imgurl,
String result = articleService.addArticle(title, content, imgurl); @RequestParam(value = "type", required = false) Integer type) {
String result = articleService.addArticle(title, content, imgurl,type);
if (result.equals("ok")) { if (result.equals("ok")) {
return new Vo_msg(0, null, "添加成功"); return new Vo_msg(0, null, "添加成功");
} else { } else {
...@@ -58,8 +60,9 @@ public class ArticlesController extends BaseController { ...@@ -58,8 +60,9 @@ public class ArticlesController extends BaseController {
// 修改 // 修改
@RequestMapping(value = "/updateArticle", method = RequestMethod.POST) @RequestMapping(value = "/updateArticle", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Object updateArticle(Integer id, String title, String content, String imgurl) { public Object updateArticle(Integer id, String title, String content, String imgurl,
String result = articleService.updateArticle(id, title, content, imgurl); @RequestParam(value = "type", required = false) Integer type) {
String result = articleService.updateArticle(id, title, content, imgurl,type);
if (result.equals("ok")) { if (result.equals("ok")) {
return new Vo_msg(0, "修改成功"); return new Vo_msg(0, "修改成功");
} else { } else {
......
...@@ -158,7 +158,7 @@ public class WxMiniController extends BaseController { ...@@ -158,7 +158,7 @@ public class WxMiniController extends BaseController {
@ResponseBody @ResponseBody
public Object getArticlesList(Integer page, Integer pagesize) { 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,90 +5,38 @@ import java.util.Date; ...@@ -5,90 +5,38 @@ import java.util.Date;
import javax.persistence.Id; import javax.persistence.Id;
public class Articles { 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 @Id
private Integer 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; 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; 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; 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; 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; private Boolean deleted;
private Integer type;
/**
* 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; private String content;
/** public Integer getType() {
* This method was generated by MyBatis Generator. return type;
* This method returns the value of the database column articles.id }
*
* @return the value of articles.id public void setType(Integer type) {
* this.type = type;
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 }
*/
public Integer getId() { public Integer getId() {
return id; 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) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.title * of the database column articles.title
* *
* @return the value of articles.title * @return the value of articles.title
* *
...@@ -99,10 +47,11 @@ public class Articles { ...@@ -99,10 +47,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.title * the database column articles.title
* *
* @param title the value for articles.title * @param title
* the value for articles.title
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
...@@ -111,8 +60,8 @@ public class Articles { ...@@ -111,8 +60,8 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.imgurl * of the database column articles.imgurl
* *
* @return the value of articles.imgurl * @return the value of articles.imgurl
* *
...@@ -123,10 +72,11 @@ public class Articles { ...@@ -123,10 +72,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.imgurl * the database column articles.imgurl
* *
* @param imgurl the value for articles.imgurl * @param imgurl
* the value for articles.imgurl
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
...@@ -135,8 +85,8 @@ public class Articles { ...@@ -135,8 +85,8 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.createdtime * of the database column articles.createdtime
* *
* @return the value of articles.createdtime * @return the value of articles.createdtime
* *
...@@ -147,10 +97,11 @@ public class Articles { ...@@ -147,10 +97,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.createdtime * the database column articles.createdtime
* *
* @param createdtime the value for articles.createdtime * @param createdtime
* the value for articles.createdtime
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
...@@ -159,8 +110,8 @@ public class Articles { ...@@ -159,8 +110,8 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.viewcount * of the database column articles.viewcount
* *
* @return the value of articles.viewcount * @return the value of articles.viewcount
* *
...@@ -171,10 +122,11 @@ public class Articles { ...@@ -171,10 +122,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.viewcount * the database column articles.viewcount
* *
* @param viewcount the value for articles.viewcount * @param viewcount
* the value for articles.viewcount
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
...@@ -183,8 +135,8 @@ public class Articles { ...@@ -183,8 +135,8 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.deleted * of the database column articles.deleted
* *
* @return the value of articles.deleted * @return the value of articles.deleted
* *
...@@ -195,10 +147,11 @@ public class Articles { ...@@ -195,10 +147,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.deleted * the database column articles.deleted
* *
* @param deleted the value for articles.deleted * @param deleted
* the value for articles.deleted
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
...@@ -207,8 +160,8 @@ public class Articles { ...@@ -207,8 +160,8 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method returns the value
* This method returns the value of the database column articles.content * of the database column articles.content
* *
* @return the value of articles.content * @return the value of articles.content
* *
...@@ -219,10 +172,11 @@ public class Articles { ...@@ -219,10 +172,11 @@ public class Articles {
} }
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator. This method sets the value of
* This method sets the value of the database column articles.content * the database column articles.content
* *
* @param content the value for articles.content * @param content
* the value for articles.content
* *
* @mbggenerated Wed Nov 22 10:09:40 CST 2017 * @mbggenerated Wed Nov 22 10:09:40 CST 2017
*/ */
......
...@@ -57,7 +57,7 @@ public class ArticleService{ ...@@ -57,7 +57,7 @@ public class ArticleService{
@Autowired @Autowired
ArticlesDao articleDao; 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; if(StringUtil.isZearoOrNull(pagesize))pagesize=10;
Example example = new Example(Articles.class); Example example = new Example(Articles.class);
example.createCriteria().andEqualTo("deleted", false); example.createCriteria().andEqualTo("deleted", false);
...@@ -65,6 +65,9 @@ public class ArticleService{ ...@@ -65,6 +65,9 @@ public class ArticleService{
if(!Strings.isNullOrEmpty(keyword)){ if(!Strings.isNullOrEmpty(keyword)){
example.createCriteria().andLike("title", "%"+keyword+"%"); example.createCriteria().andLike("title", "%"+keyword+"%");
} }
if(type!=null && type>0) {
example.createCriteria().andEqualTo("type",type);
}
example.setOrderByClause(" id desc "); example.setOrderByClause(" id desc ");
List<Articles> list = articleDao.selectByExampleAndRowBounds(example, row); List<Articles> list = articleDao.selectByExampleAndRowBounds(example, row);
int total = articleDao.selectCountByExample(example); int total = articleDao.selectCountByExample(example);
...@@ -76,7 +79,7 @@ public class ArticleService{ ...@@ -76,7 +79,7 @@ public class ArticleService{
return pageresult; 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 // TODO Auto-generated method stub
Articles article=new Articles(); Articles article=new Articles();
article.setTitle(title); article.setTitle(title);
...@@ -85,22 +88,19 @@ public class ArticleService{ ...@@ -85,22 +88,19 @@ public class ArticleService{
article.setCreatedtime(CommonUtil.getTime()); article.setCreatedtime(CommonUtil.getTime());
article.setDeleted(false); article.setDeleted(false);
article.setViewcount(0); article.setViewcount(0);
article.setType(type);
int row = articleDao.insertSelective(article); int row = articleDao.insertSelective(article);
return row > 0 ? "ok" : "添加失败,数据异常"; return row > 0 ? "ok" : "添加失败,数据异常";
} }
/* (非 Javadoc) public String updateArticle(Integer id, String title, String content, String imgurl,Integer type) {
* 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) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Articles article=articleDao.selectByPrimaryKey(id); Articles article=articleDao.selectByPrimaryKey(id);
if(article==null)return "修改失败,数据不存在"; if(article==null)return "修改失败,数据不存在";
article.setTitle(title); article.setTitle(title);
article.setContent(content); article.setContent(content);
article.setImgurl(imgurl); article.setImgurl(imgurl);
article.setType(type);
int row = articleDao.updateByPrimaryKeySelective(article); int row = articleDao.updateByPrimaryKeySelective(article);
return row > 0 ? "ok" : "修改失败,数据异常"; return row > 0 ? "ok" : "修改失败,数据异常";
} }
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!