Skip to content

Commit

Permalink
增加freemarker
Browse files Browse the repository at this point in the history
  • Loading branch information
yita committed May 17, 2015
1 parent d42e4de commit 4552608
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<artifactId>spring-webmvc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>

<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
Expand All @@ -126,6 +131,14 @@
</dependency>
<!-- WEB end -->

<!-- template engine begin-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>

<!-- template engine end-->

<!-- SECURITY begin -->
<dependency>
<groupId>org.apache.shiro</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.springside.examples.quickstart.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
* freemarker 测试
* @author yintao yin.tao@foxmail.com
*/
@Controller
@RequestMapping(value = "/freemarker")
public class FreemarkerController {
private final Logger logger = LoggerFactory.getLogger(FreemarkerController.class);

@RequestMapping(method = RequestMethod.GET)
public String welcome() {
logger.debug("in ftl controller");
return "freemarker";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/static/** = anon
/api/** = anon
/register/** = anon
/freemarker = anon
/admin/** = roles[admin]
/** = user
</value>
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</appender>

<!-- project default level -->
<logger name="org.springside.examples.quickstart" level="INFO" />
<logger name="org.springside.examples.quickstart" level="DEBUG" />

<!--log4jdbc -->
<logger name="jdbc.sqltiming" level="INFO"/>
Expand Down
33 changes: 33 additions & 0 deletions examples/quickstart/src/main/webapp/WEB-INF/spring-mvc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,42 @@

<!-- 定义JSP文件的位置 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="1" />
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>

<!-- freemarker config -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/views/"/>
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
</map>
</property>
<property name="defaultEncoding" value="UTF-8"/>
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">3600</prop>
<prop key="locale">zh_CN</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="number_format">#.##</prop>
</props>
</property>
</bean>
<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>

<!--
View resolvers can also be configured with ResourceBundles or XML files. If you need
different view resolving based on Locale, you have to use the resource bundle resolver.
-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true"/>
<property name="order" value="0" />
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
</bean>


<!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome use freemarker!

0 comments on commit 4552608

Please sign in to comment.