use of com.myblog.model.Blog in project newblogback by Zephery.
the class TagServiceImpl method updatetag.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Integer updatetag(Integer tId) {
// 标签
List<Tag> tags = tagMapper.getAllTags();
JsonArray jsonArray = new JsonArray();
for (Tag tag : tags) {
List<Blog> blogs = tagMapper.getblogbytagid(tag.gettId());
String str = tag.gettName() + " " + "(" + String.valueOf(blogs.size()) + ")";
KeyAndValue keyAndValue = new KeyAndValue();
keyAndValue.setKey(tag.gettName());
keyAndValue.setValue(str);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("key", tag.gettId());
jsonObject.addProperty("value", str);
jsonArray.add(jsonObject);
}
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
connection.set(serializer.serialize("biaoqian"), serializer.serialize(jsonArray.toString()));
return true;
}
});
return tId;
}
use of com.myblog.model.Blog in project micro-service by Zephery.
the class IndexController method get.
@GetMapping("/get")
public String get(Integer blogid) {
Blog blog = blogDao.getOne(blogid);
Gson gson = new Gson();
return blog.getSummary();
}
use of com.myblog.model.Blog in project newblogback by Zephery.
the class BlogController method editArticle.
@GetMapping(value = "/{cid}")
public ModelAndView editArticle(@PathVariable String cid, HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView();
Blog blog = blogService.getBlogDetail(Integer.parseInt(cid));
modelAndView.addObject("blog", blog);
List<Category> categories = categoryService.getAllCategory();
modelAndView.addObject("categories", categories);
modelAndView.addObject("active", "article");
modelAndView.setViewName("/admin/article_edit");
return modelAndView;
}
use of com.myblog.model.Blog in project newblogback by Zephery.
the class BlogServiceImpl method getBlogDetail.
@Override
public Blog getBlogDetail(Integer blogid) {
Blog blog = blogMapper.selectByPrimaryKey(blogid);
if (blog == null) {
return null;
}
Category category = categoryMapper.selectByPrimaryKey(blog.getCategoryid());
blog.setCategory(category);
List<Tag> tags = tagMapper.getTagByBlogId(blog.getBlogid());
List<String> list = new ArrayList<>();
for (Tag tag : tags) {
list.add(tag.gettName());
}
blog.setTagforsplit(StringUtils.join(list, ","));
blog.setTags(tags.size() > 0 ? tags : null);
if (blogMapper.updatehits(blogid)) {
logger.info("read count success");
} else {
logger.info("read count failure");
}
return blog;
}
use of com.myblog.model.Blog in project newblogback by Zephery.
the class BlogServiceImpl method insertblog.
@Override
public synchronized Integer insertblog(Blog blog) {
blog.setSummary(blog.getContent().length() > 120 ? blog.getContent().substring(0, 120) : blog.getContent());
blog.setCreateAt(DateTime.now().toString("yyyy-MM-dd"));
Matcher matcher = Pattern.compile(IMGSRC_REG).matcher(blog.getContent());
String image_url = null;
while (matcher.find()) {
image_url = matcher.group();
}
// http://image.wenzhihuai.com/images/20171018051437.png?imageInfo
// {"size":14736,"format":"png","width":667,"height":387,"colorModel":"rgba"}
blog.setImageurl(getImageURl(image_url));
String[] array = blog.getTagforsplit().split(",");
List<Tag> tags = new ArrayList<>();
for (String string : array) {
if (tagMapper.selectByName(string) == null) {
Tag tag = new Tag();
tag.settName(string);
tagMapper.insertSelective(tag);
Tag newtag = tagMapper.selectByName(string);
tags.add(newtag);
// tag.settId(tId);//TODO 返回主键长不起作用
// tags.add(tag);
} else {
tags.add(tagMapper.selectByName(string));
}
}
blog.setTags(tags.size() == 0 ? null : tags);
blog.setHits(0);
blog.setContent(StringEscapeUtils.escapeSql(blog.getContent()));
blogMapper.insert(blog);
Blog newblog = blogMapper.selectByTitle(blog.getTitle());
if (tags.size() > 0) {
for (Tag tag : tags) {
Relation relation = new Relation();
relation.setBlogid(newblog.getBlogid());
relation.settId(tag.gettId());
relationMapper.insert(relation);
}
}
return blogMapper.selectMaxId();
}
Aggregations