userList.html
[code="java"]
<!DOCTYPE html>
name | age | sex |
---|---|---|
[/code]
dispatcher-servlet.xml
[code="java"]
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
<bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<property name="order" value="1" />
<property name="viewNames" value="thymeleafe/*" />
</bean>
[/code]
ThymeleafeControler
[code="java"]
package com.cn.ld.modules.thymeleaf;
import java.util.List;
@RequestMapping("/thymeleafe/")
@Controller
public class ThymeleafeControler {
@Autowired
private UserService userService;
@RequestMapping("userList")
public String goSerchUserH(HttpServletResponse response) {
return "userList";
}
@ModelAttribute("allUsers")
public List<User> getAllUsers(){
return this.userService.getUserList();
}
@RequestMapping("save")
public void save(User user){
this.userService.addUser(user);
}
@RequestMapping("remove")
public void save(String name){
User u = this.userService.findByName(name);
this.userService.removeUser(u);
}
}
[/code]
web.xml
[code="java"]
<!-- 字符集 过滤器 -->
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
[/code]
pom.xml
[code="java"]
<!-- thymeleaf -->
org.thymeleaf
thymeleaf-spring3
2.0.17
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>2.0.17</version>
</dependency>
[/code]
[img]http://dl2.iteye.com/upload/attachment/0086/6304/9fc69b75-4a27-3ed3-b262-77fd356fc4f0.png[/img]