我只是想用Spring MVC學習磁貼。我之前沒有使用瓷磚。隨函附上代碼:在Spring MVC中使用磁貼
servlet.xml中
<context:component-scan base-package="org.sparsham.sparshammanagement.controllers" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /> <property name="prefix" value="/WEB-INF/pages"/> <property name="suffix" value=".jsp"></property> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles.xml</value> </list> </property> </bean>
我Tiles.xml
<tiles-definitions> <definition name="base.definition" template="/WEB-INF/pages/layout.jsp"> <put-attribute name="title" value="" /> <put-attribute name="header" value="/WEB-INF/pages/layout/header.jsp" /> <put-attribute name="menu" value="/WEB-INF/pages/layout/menu.jsp" /> <put-attribute name="body" value="" /> <put-attribute name="footer" value="/WEB-INF/pages/layout/footer.jsp" /> </definition> </tiles-definitions>
然後我創建了佈局頁眉和頁腳。
@Controller
@RequestMapping("/")
public class Default {
@RequestMapping("index")
public String index(){
return "Sparsham";
}
@RequestMapping("*")
public String unhandled(){
return "error404";
}
}
什麼是下一個步驟?