Skip to content

Commit 41c7b37

Browse files
author
unknown
committed
free marker
1 parent 4cd3aca commit 41c7b37

File tree

10 files changed

+219
-0
lines changed

10 files changed

+219
-0
lines changed

spring-freemarker-example/pom.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<packaging>war</packaging>
7+
8+
<groupId>com.vonzhou.learning</groupId>
9+
<artifactId>spring-freemarker-example</artifactId>
10+
<version>1.0</version>
11+
12+
<properties>
13+
<project.build.souceEncoding>UTF-8</project.build.souceEncoding>
14+
<spring.version>3.0.5.RELEASE</spring.version>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework</groupId>
19+
<artifactId>spring-core</artifactId>
20+
<version>${spring.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework</groupId>
24+
<artifactId>spring-beans</artifactId>
25+
<version>${spring.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-web</artifactId>
30+
<version>${spring.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-context</artifactId>
35+
<version>${spring.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-context-support</artifactId>
40+
<version>${spring.version}</version>
41+
</dependency>
42+
43+
<!-- Spring MVC -->
44+
<dependency>
45+
<groupId>org.springframework</groupId>
46+
<artifactId>spring-webmvc</artifactId>
47+
<version>${spring.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>javax.servlet</groupId>
51+
<artifactId>servlet-api</artifactId>
52+
<version>2.5</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
56+
<!--freemarker-->
57+
<dependency>
58+
<groupId>org.freemarker</groupId>
59+
<artifactId>freemarker</artifactId>
60+
<version>2.3.16</version>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>log4j</groupId>
65+
<artifactId>log4j</artifactId>
66+
<version>1.2.17</version>
67+
</dependency>
68+
</dependencies>
69+
70+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.vonzhou.simple.controller;
2+
3+
import com.vonzhou.simple.domain.User;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.servlet.ModelAndView;
8+
9+
/**
10+
* Created by vonzhou on 2016/8/12.
11+
*/
12+
@Controller
13+
@RequestMapping("/app")
14+
public class SimpleController {
15+
16+
@RequestMapping("/hello")
17+
public ModelAndView hello(@RequestParam("name") String name, ModelAndView modelAndView){
18+
User user = new User();
19+
user.setName(name);
20+
user.setTag("You are great!");
21+
22+
modelAndView.addObject("user", user);
23+
modelAndView.setViewName("hello.ftl");
24+
return modelAndView;
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.vonzhou.simple.domain;
2+
3+
4+
public class User {
5+
private String name;
6+
private String tag;
7+
8+
public String getName() {
9+
return name;
10+
}
11+
12+
public void setName(String name) {
13+
this.name = name;
14+
}
15+
16+
public String getTag() {
17+
return tag;
18+
}
19+
20+
public void setTag(String tag) {
21+
this.tag = tag;
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#mysql 数据库配置
2+
3+
jdbc.driverClassName=com.mysql.jdbc.Driver
4+
jdbc.url=jdbc:mysql://localhost:3306/spitter?useUnicode=true&amp;characterEncoding=UTF-8
5+
jdbc.username=root
6+
jdbc.password=
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### set log levels - for more verbose logging change 'info' to 'debug' ###
2+
log4j.rootLogger =info, stdout
3+
4+
### direct log messages to stdout ###
5+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6+
log4j.appender.stdout.Target=System.out
7+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
8+
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
9+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:aop="http://www.springframework.org/schema/aop"
5+
xmlns:tx="http://www.springframework.org/schema/tx"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xmlns:context="http://www.springframework.org/schema/context"
8+
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
9+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
10+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
11+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
12+
13+
<context:component-scan base-package="com.vonzhou.learning.controller" />
14+
15+
16+
17+
18+
19+
</beans>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:mvc="http://www.springframework.org/schema/mvc"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation="http://www.springframework.org/schema/mvc
7+
http://www.springframework.org/schema/mvc/spring-mvc.xsd
8+
http://www.springframework.org/schema/beans
9+
http://www.springframework.org/schema/beans/spring-beans.xsd
10+
http://www.springframework.org/schema/context
11+
http://www.springframework.org/schema/context/spring-context.xsd
12+
">
13+
14+
<mvc:resources mapping="/resources/**" location="/resources/"/>
15+
<mvc:annotation-driven/>
16+
<context:component-scan base-package="com.vonzhou.simple.controller"/>
17+
18+
<bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
19+
<property name="templateLoaderPath" value="/WEB-INF/views/"/>
20+
<property name="freemarkerSettings">
21+
<props>
22+
<prop key="defaultEncoding">UTF-8</prop>
23+
<prop key="number_format">0</prop>
24+
</props>
25+
</property>
26+
</bean>
27+
28+
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
29+
<property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
30+
<property name="contentType" value="text/html;charset=UTF-8"/>
31+
<property name="suffix" value=".ftl"/>
32+
</bean>
33+
34+
35+
</beans>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Free Marker Example</h1>
2+
3+
Your Name: $user
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
5+
version="3.0">
6+
7+
<servlet>
8+
<servlet-name>simple</servlet-name>
9+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
10+
<load-on-startup>1</load-on-startup>
11+
</servlet>
12+
13+
14+
<servlet-mapping>
15+
<servlet-name>simple</servlet-name>
16+
<url-pattern>*.do</url-pattern>
17+
</servlet-mapping>
18+
19+
<listener>
20+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
21+
</listener>
22+
<context-param>
23+
<param-name>contextConfigLocation</param-name>
24+
<param-value>
25+
/WEB-INF/simple-servlet.xml
26+
</param-value>
27+
</context-param>
28+
</web-app>
Loading

0 commit comments

Comments
 (0)