필요한 설정을 기억하기 위해 기록합니다.
VelocityTools는 벨로시티 템플릿에서 숫자나 날짜, url등의 포맷팅을 지원하는 툴이고,
VelocityTools프로젝트에는 GenericTools, VelocityView, VelocityStruts 세개의 부분으로 나눠져 있습니다.
보통 GenericTools를 많이 쓸일이 많기 때문에~ 조금 정리해보면,
- DateTool
- A tool for manipulating and formatting dates.
- MathTool
- A tool for performing floating point math.
- NumberTool
- A tool for formatting numbers.
- RenderTool
- A tool to evaluate and render arbitrary strings of VTL (Velocity Template Language).
- EscapeTool
- A tool to help with common escaping needs in Velocity templates.
- ResourceTool
- A tool to simplify access to ResourceBundles for internationalization or other dynamic content needs.
- Alternator and AlternatorTool
- Utility class for easily alternating over values in a list and tool for easy creation of Alternators in templates.
- ValueParser
- A tool to retrieve and parse String values pulled from a map. This provides the basis for the ParameterParser in VelocityView.
- ListTool
- A tool to help when working with arrays or Lists. This tool transparently handles both the same way.
- SortTool
- A tool that allows a user to sort a collection (or array, iterator, etc) on any arbitary set of properties exposed by the objects contained within the collection.
- IteratorTool
- A convenience tool to use with #foreach loops. It wraps a list to let the designer specify a condition to terminate the loop, and reuse the same list in different loops.
EscapeTool
- It provides methods to escape outputs for Java, JavaScript, HTML, HTTP, XML and SQL. Also provides methods to render VTL characters that otherwise needs escaping.
을 이용하여 테스트 해보면...
toolbox.xml 파일을 하나 만들어서
<?xml version="1.0"?>
<toolbox>
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>
<toolbox>
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>
genericTool의 EscapeTool을 사용하는데 velocity에서 esc라는 키워드를 이용해서 쓰겠다~
스프링에서 Properties파일을 따로 정의했다고 하면(따로 빼 놓았다면)
# velocityViewResolver
velocity.resourceLoaderPath=/WEB-INF/velocity/
velocity.toolboxConfigLocation=/WEB-INF/spring/toolbox.xml
velocity.properties=/WEB-INF/spring/velocity.properties
velocity.overrideLogging=false
velocity.cache=false
velocity.prefix=
velocity.suffix=.vm
velocity.resourceLoaderPath=/WEB-INF/velocity/
velocity.toolboxConfigLocation=/WEB-INF/spring/toolbox.xml
velocity.properties=/WEB-INF/spring/velocity.properties
velocity.overrideLogging=false
velocity.cache=false
velocity.prefix=
velocity.suffix=.vm
스프링의 설정파일에서
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="${velocity.cache}" />
<property name="prefix" value="${velocity.prefix}" />
<property name="suffix" value="${velocity.suffix}" />
<property name="toolboxConfigLocation" value="${velocity.toolboxConfigLocation}" />
<property name="exposeSpringMacroHelpers" value="true" />
</bean>
<property name="cache" value="${velocity.cache}" />
<property name="prefix" value="${velocity.prefix}" />
<property name="suffix" value="${velocity.suffix}" />
<property name="toolboxConfigLocation" value="${velocity.toolboxConfigLocation}" />
<property name="exposeSpringMacroHelpers" value="true" />
</bean>
.vm라는 확장자의 velocity파일에서
$esc.xml("< >")
결과는
< >
참고 :
[Velocity] 스프링 프레임워크에서 사용하기
http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/EscapeTool.htmlhttp://forum.springframework.org/archive/index.php/t-10926.html
'나만의 작업 > Spring' 카테고리의 다른 글
[Junit5] SpringBoot2+Junit5 에서 TestEngine with ID 'junit-jupiter' failed to discover tests 오류 해결방법 (0) | 2019.07.26 |
---|---|
[Spring] Lazy Initialization in Spring Boot 2.2 - 번역 (0) | 2019.07.16 |
[SpringSecurity] Authentication(인증) 관련 클래스와 처리 (0) | 2016.01.25 |
[Spring] @Autowired의 Before/After (2) | 2009.04.29 |
[Spring] 스프링에서 VelocityTools 환경설정 (2) | 2008.03.20 |
[Spring] 스프링 MVC를 이용한 웹 요청 처리 (4) | 2008.03.13 |
[Spring] Bean과 BeanFactory의 후처리 (8) | 2008.02.12 |
[Spring] 자동 묶기(Autowire) (2) | 2008.02.12 |
[Spring] 세터 주입(Setter Injection)의 대안 (5) | 2008.02.05 |
좋은정보 감사합니다. :-)
^^;;;; 그럼 전 방문해 주셔서 감사합니다.