这篇文章主要介绍了springboot中jsp配置tiles全过程,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
tiles是jsp的前端框架;像fream标签一样可以把多个页面组合起来;
完成后的目录结构:
1.pom.xml中添加依赖
      <!-- Add Apache Tiles into the mix -->
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>3.0.4</version>
        </dependency>2.新建 tiles.xml
可以放在WEB-INF/tiles/目录里
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>
    <!-- Templates -->
    <definition name="layout.basic" template="/WEB-INF/tiles/basic.jsp">
        <put-attribute name="title" value="Spring Web MVC with Tiles 3" />
        <put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
    </definition>
    <!-- Pages -->  
    <definition name="site.homepage" extends="layout.basic">
        <put-attribute name="body" value="/WEB-INF/tiles/home.jsp" />
    </definition>
</tiles-definitions>3.新建tiles配置类ConfigurationForTiles.java
@Configuration
public class ConfigurationForTiles {
    /**
     * Initialise Tiles on application startup and identify the location of the tiles configuration file, tiles.xml.
     * 
     * @return tiles configurer
     */
    @Bean
    public TilesConfigurer tilesConfigurer() {
        final TilesConfigurer configurer = new TilesConfigurer();
        configurer.setDefinitions(new String[] { "WEB-INF/tiles/tiles.xml" });
        configurer.setCheckRefresh(true);
        return configurer;
    }
    /**
     * Introduce a Tiles view resolver, this is a convenience implementation that extends URLBasedViewResolver.
     * 
     * @return tiles view resolver
     */
    @Bean
    public TilesViewResolver tilesViewResolver() {
        final TilesViewResolver resolver = new TilesViewResolver();
        resolver.setViewClass(TilesView.class);
        return resolver;
    }
}注意tiles.xml文件目录要正确;
4.jsp
1. basic.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
    <head>
        <title><tiles:getAsString name="title" /></title>
    </head>
    <body>
    basic.jsp
        <!-- Header -->
        <tiles:insertAttribute name="header" />
        <!-- Body -->
        <tiles:insertAttribute name="body" />
        <!-- Footer -->
        <tiles:insertAttribute name="footer" />
    </body>
</html>2.footer.jsp
<div>The Footer   footer.jsp</div>3.header.jsp
<div>The Header header.jsp</div>4.home.jsp
<div>
    Main content would go here. Lets try.     home.jsp
</div>5.控制类
@Controller
public class GreetingController {
    private Log log = LogFactory.getLog(this.getClass());
    @RequestMapping(value = "/home", method=RequestMethod.GET)
    public String home() {
        return "site.homepage";  //这个是    definition 的  name="site.homepage"
    }
}6.测试
完成!
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程学习网。
				 沃梦达教程
				
			本文标题为:springboot中jsp配置tiles全过程
				
        
 
            
        
             猜你喜欢
        
	     - Java实现顺序表的操作详解 2023-05-19
 - Springboot整合minio实现文件服务的教程详解 2022-12-03
 - JSP页面间传值问题实例简析 2023-08-03
 - JSP 制作验证码的实例详解 2023-07-30
 - SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
 - Java中的日期时间处理及格式化处理 2023-04-18
 - ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
 - Spring Security权限想要细化到按钮实现示例 2023-03-07
 - 深入了解Spring的事务传播机制 2023-06-02
 - 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
 
						
						
						
						
						
				
				
				
				