IT俱乐部 Java springboot中jsp配置tiles全过程

springboot中jsp配置tiles全过程

tiles是jsp的前端框架;像fream标签一样可以把多个页面组合起来;

完成后的目录结构:

1.pom.xml中添加依赖

      
        org.apache.tilestiles-jsp3.0.4

2.新建 tiles.xml

可以放在WEB-INF/tiles/目录里


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


    
        
    basic.jsp
        
        

2.footer.jsp

The Footer footer.jsp

3.header.jsp

The Header header.jsp

4.home.jsp

Main content would go here. Lets try. home.jsp

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.测试

完成!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/code/java/6845.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部