Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | About

6.4. View

6.4.1. Using Spring’s form tag library

6.4.1.1. css
			
	
			
			
6.4.1.1.1. cssClass

cssClass 使用该属性指定表单元素CSS样式名,相当于HTML元素的class属性

				
<form:input path="userName" cssClass="inputStyle"/>
				
				
6.4.1.1.2. cssStyle

cssStyle 直接通过该属性指定样式,相当于HTML元素的style属性

				
<form:input path="userName" cssStyle="width:100px"/>
				
				
6.4.1.1.3. cssErrorClass

cssError Class表示表单元素发生错误时对应的样式

				
<form:input path="userName" cssClass="userNameClass" cssErrorClass= "userNameClassError"/>
				
				
6.4.1.2. cssClass
			
	
			
			

6.4.2. Thymeleaf

http://thymeleaf.org/

6.4.2.1. Maven pom.xml
			
			<dependency>  
	            <groupId>org.springframework.boot</groupId>  
	            <artifactId>spring-boot-starter-thymeleaf</artifactId>  
	        </dependency>  		
			
			
6.4.2.2. Spring 配置
			
	<!-- **************************************************************** -->
	<!-- THYMELEAF-SPECIFIC ARTIFACTS -->
	<!-- TemplateResolver <- TemplateEngine <- ViewResolver -->
	<!-- **************************************************************** -->

	<bean id="templateResolver"
		class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
		<property name="prefix" value="/WEB-INF/templates/" />
		<property name="suffix" value=".html" />
		<property name="templateMode" value="HTML5" />
	</bean>

	<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
		<property name="templateResolver" ref="templateResolver" />
	</bean>

	<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
		<property name="templateEngine" ref="templateEngine" />
	</bean>	
			
			
6.4.2.3. controller
			
package cn.netkiller.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class HelloController {

	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
	public String getMovie(@PathVariable String name, ModelMap model) {
		model.addAttribute("name", name);
		return "hello";
	}

}			
			
			
6.4.2.4. HTML5 Template
			
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Spring MVC + Thymeleaf Example</title>
</head>
<body>
	Hello, <span th:text="${name}" />!
</body>
</html>
			
			

6.4.3. FreeMarker

http://freemarker.org/