activiti工作流解决历史批注中文乱码

/**
 * 根据流程实例查询流程的批注信息
 *
 * @param processInstanceId
 * @return
 */
private List<Comment> findCommentByProcessInstanceId(String processInstanceId) {
    return taskService.getProcessInstanceComments(processInstanceId);
}

默认获取到的Comment是没有getMessage()方法的,只有getFullMessage(),getFullMessage会跟随部署的系统编码,保存到数据库中的bolb字段可能会出现乱码,但是message字段不是乱码,如果审批备注只是文字的话,可以直接取message字段的值。
查看源码得知,CommentEntityImpl 实现了Comment类接口,既可以把Comment 转换为CommentEntityImpl,直接用其中的getMessage()方法即可。

List<Comment> list = findCommentByProcessInstanceId(processInstanceId);
for (Comment commentEntity : list) {
 CommentEntityImpl comment = null;
 if(commentEntity instanceof CommentEntityImpl){
     comment = (CommentEntityImpl)commentEntity;
 }
String message = comment.getMessage();

猜你喜欢

转载自www.cnblogs.com/ygzone/p/12524920.html
今日推荐