use of com.myblog.model.KeyAndValue 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;
}
Aggregations