master
ck 5 years ago
parent 9f4fab8e15
commit d71765cdda

@ -0,0 +1,42 @@
package com.jingcheng.cms.controller;
import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.service.ArticleSerive;
import com.jingcheng.cms.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/article")
public class ArticleController {
@Autowired
private ArticleSerive articleSerive;
/**
*
* @param jsonObject
* @return
*/
@RequestMapping("/save-article")
public AjaxResult saveArticle(@RequestBody JSONObject jsonObject) {
AjaxResult ajaxResult = articleSerive.saveArticle(jsonObject);
return ajaxResult;
}
/**
*
* @param jsonObject
* @return
*/
@RequestMapping("/article-list-by-condition")
public AjaxResult getArticleListByPage(@RequestBody JSONObject jsonObject) {
AjaxResult ajaxResult = new AjaxResult();
JSONObject pageJson= articleSerive.getArticleListByPage(jsonObject);
ajaxResult.setData(pageJson);
return ajaxResult;
}
}

@ -4,7 +4,11 @@ import com.jingcheng.cms.model.Article;
import com.jingcheng.cms.util.CommonMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ArticleMapper extends CommonMapper<Article> {
int addArticle(Article article);
List<Article> getArticleListByCondition(Article article);
}

@ -33,11 +33,6 @@ public class Article extends BaseEntity{
*/
private Integer fileType;
/**
*
*/
private String filePath;
/**
*
*/

@ -4,5 +4,16 @@ import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.util.AjaxResult;
public interface ArticleSerive {
/**
*
* @param jsonObject
* @return
*/
AjaxResult saveArticle(JSONObject jsonObject);
/**
*
* @param jsonObject
* @return
*/
JSONObject getArticleListByPage(JSONObject jsonObject);
}

@ -1,15 +1,19 @@
package com.jingcheng.cms.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.constants.Constants;
import com.jingcheng.cms.mapper.ArticleMapper;
import com.jingcheng.cms.model.Article;
import com.jingcheng.cms.service.ArticleSerive;
import com.jingcheng.cms.util.AjaxResult;
import com.jingcheng.cms.util.PageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
@ -28,6 +32,7 @@ public class ArticleSerivceImpl implements ArticleSerive {
String secondCategoryName = jsonObject.getString("secondCategoryName");
String keyword = jsonObject.getString("keyword");
Integer fileType = jsonObject.getInteger("fileType");
String content = jsonObject.getString("content");
Integer state = jsonObject.getInteger("state");
if (null == state){
ajaxResult.setRetcode(AjaxResult.FAILED);
@ -49,6 +54,11 @@ public class ArticleSerivceImpl implements ArticleSerive {
ajaxResult.setRetmsg("文章形式不可为空");
return ajaxResult;
}
if (StringUtils.isBlank(content)){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章内容不可为空");
return ajaxResult;
}
if (null == id){
//新增
Article article = new Article();
@ -58,7 +68,9 @@ public class ArticleSerivceImpl implements ArticleSerive {
article.setKeyword(keyword);
article.setFileType(fileType);
article.setState(state);
article.setContent(content.getBytes());
articleMapper.addArticle(article);
ajaxResult.setRetmsg("成功新增文章");
}else {
//修改
Article article = articleMapper.selectByPrimaryKey(id);
@ -73,8 +85,31 @@ public class ArticleSerivceImpl implements ArticleSerive {
article.setKeyword(keyword);
article.setFileType(fileType);
article.setState(state);
article.setContent(content.getBytes());
articleMapper.updateByPrimaryKeySelective(article);
ajaxResult.setRetmsg("成功修改文章");
}
return null;
return ajaxResult;
}
@Override
public JSONObject getArticleListByPage(JSONObject jsonObject) {
Integer pageNum = jsonObject.getInteger("pageNum") == null ? 1 : jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize") == null ? 5 : jsonObject.getInteger("pageSize");
String title = jsonObject.getString("title");
String categoryName = jsonObject.getString("categoryName");
Integer fileType = jsonObject.getInteger("fileType");
Integer state = jsonObject.getInteger("state");
Article article = new Article();
article.setTitle(title);
article.setFirstCategoryName(categoryName);
article.setFileType(fileType);
article.setState(state);
List<Article> CategoryList = articleMapper.getArticleListByCondition(article);
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
return pageJson;
}
}

@ -3,7 +3,26 @@
<mapper namespace="com.jingcheng.cms.mapper.ArticleMapper">
<insert id="addArticle" parameterType="com.jingcheng.cms.model.Article">
INSERT INTO article(`title`,``,`type_name`,`sort_num`)
values (#{name},#{level},#{typeName},#{sortNum})
INSERT INTO article(`title`,`first_category_name`,`second_category_name`,`keyword`,`file_type`,`content`,`state`)
values (#{title},#{firstCategoryName},#{secondCategoryName},#{keyword},#{fileType},#{content},#{state})
</insert>
<select id="getArticleListByCondition" parameterType="com.jingcheng.cms.model.Article" resultType="com.jingcheng.cms.model.Article">
select `id`,`title`,`first_category_name`,`second_category_name`,`keyword`,`file_type`,`content`,`create_date_time`,
`update_date_time`,`state` FROM article
where
1 = 1
<if test="title != null and title != ''">
and title LIKE CONCAT('%',#{title},'%')
</if>
<if test="firstCategoryName != null and firstCategoryName != ''">
and (first_category_name LIKE CONCAT('%',#{firstCategoryName},'%') or second_category_name LIKE CONCAT('%',#{firstCategoryName},'%'))
</if>
<if test="fileType != null ">
and file_type = #{fileType}
</if>
<if test="state != null ">
and state = #{state}
</if>
</select>
</mapper>
Loading…
Cancel
Save