Spring 3.2 + Apache Tiles 3

controller
@Controller
public class LoginController {

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public ModelAndView getContent() {

		ModelAndView view = new ModelAndView("loginView");

		return view;
	}
}

spring-servlet.xml
	<bean id="tilesConfigurer"
		class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
		<property name="definitions">
			<list>
				<value>/WEB-INF/tiles.xml</value>
			</list>
		</property>
		<property name="preparerFactoryClass"
			value="org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory" />
	</bean>
	
	<bean id="tilesViewResolver"
		class="org.springframework.web.servlet.view.UrlBasedViewResolver">
		<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
	</bean>


tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
	<definition name="base.definition" template="/WEB-INF/jsp/layout.jsp">
		<put-attribute name="title" value="" />
		<put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
		<put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
		<put-attribute name="body" value="" />
		<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
	</definition>

	<definition name="loginView" extends="base.definition">
		<put-attribute name="title" value="Login Page" />
		<put-attribute name="body" value="/WEB-INF/jsp/login.jsp" />
	</definition>

</tiles-definitions>


Apache Tiles in web.xml - Starting Tiles engine
If you use springframework, does not need to do it.

If you want to configure multiple view resolvers in spring MVC
Configure Multiple View Resolvers Priority In Spring MVC


Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse

你可能感兴趣的:(spring,mvc,tiles)