Activiti在linux上出现流程图中文乱码的问题

本文介绍了两种解决Activiti在Linux环境下显示流程图中文乱码的方法:一是修改Linux系统字体,二是调整JDK的字体配置。在JDK15及以后的版本,可以在JRE的fonts/fallback目录下添加中文字体。此外,对于新版Activiti出现的属性名称中文乱码,解决方法是在返回JSON字符串时指定UTF-8编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一种解决方案就是将linux的添加中文的font

public InputStream tracePhoto(String processDefinitionId, String executionId) {
List<String> activeActivityIds = Lists.newArrayList(), highLightedFlows = new ArrayList<String>();
if (runtimeService.createExecutionQuery().executionId(executionId).count() > 0) {
activeActivityIds = runtimeService.getActiveActivityIds(executionId);
}
/**
* 获得当前活动的节点
*/
if (this.isFinished(executionId)) {// 如果流程已经结束,则得到结束节点
activeActivityIds.add(historyService.createHistoricActivityInstanceQuery().executionId(executionId)
.activityType("endEvent").singleResult().getActivityId());
} else {// 如果流程没有结束,则取当前活动节点
// 根据流程实例ID获得当前处于活动状态的ActivityId合集
activeActivityIds = runtimeService.getActiveActivityIds(executionId);
}
// 获得历史活动记录实体(通过启动时间正序排序,不然有的线可以绘制不出来)
List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
.executionId(executionId).orderByHistoricActivityInstanceStartTime().asc().list();
// 计算活动线
highLightedFlows = this
.getHighLightedFlows((ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(processDefinitionId), historicActivityInstances);
/**
* 绘制图形
*/
InputStream imageStream = null;
if (null != activeActivityIds) {
try {
// 获得流程引擎配置
ProcessEngineConfiguration processEngineConfiguration = processEngine.getProcessEngineConfiguration();
// 根据流程定义ID获得BpmnModel
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
// 输出资源内容到相应对象
imageStream = new DefaultProcessDiagramGenerator().generateDiagram(bpmnModel, "png", activeActivityIds,
highLightedFlows, processEngineConfiguration.getActivityFontName(),
processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getClassLoader(),
1.0);
return imageStream;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}


第二种是在tomcat中直接适应一下linux的系统建议使用第二种。
在jdk15以后,只需在~/jre/lib/fonts/下建一个fallback目录,把你想在java中使用的字体烤贝到这个目录中即可
以下方法在fc6下测试通过,假设用户的jre路径为 /usr/java/jdk1.7.63/jre/
  cd /usr/java/jdk1.7.63/jre/lib/fonts
  sudo mkdir fallback
将C:\WINDOWS\Fonts\simsun.ttc拷贝到 /usr/java//jdk1.7.63/jre/lib/fonts/fallback文件夹内
  好的你重启服务器试试。估计是OK的了

[b]新版出现属性名称中文乱码问题[/b]
在新版的中文属性名字的title时候出现中文乱码是由于你返回的流转化为jsonString时候需要指定解析编码格式,
在requestMap上添加method = RequestMethod.GET, produces = "application/json;charset=utf-8"

@RequestMapping(value = "editor/stencilset",
method = RequestMethod.GET, produces = "application/json;charset=utf-8")
@ResponseBody
public String stencilset() {
InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
try {
return IOUtils.toString(stencilsetStream, "utf-8");
} catch (Exception e) {
throw new RuntimeException("Error while loading stencil set", e);
} finally {
IOUtils.closeQuietly(stencilsetStream);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值