velocity 调用hutool 实现首字母大写

1.pom引入

		<dependency>
			<groupId>org.apache.velocitygroupId>
			<artifactId>velocityartifactId>
			<version>1.7version>
		dependency>
		<dependency>
            <groupId>cn.hutoolgroupId>
            <artifactId>hutool-coreartifactId>
            <version>5.8.20version>
        dependency>

2. 注册class

VelocityContext velocityContext = new VelocityContext();
velocityContext.put("hutoolStrUtil",cn.hutool.core.util.StrUtil.class);


// 渲染模板
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate("/.../..", Constants.UTF8);
            tpl.merge(velocityContext, sw);

3.模板输出

$hutoolStrUtil.upperFirst($column.javaField)

就能实现首字母大写

你可能感兴趣的:(Java项目,java)