如何删除特定视图的apache切片中的切片?

 喵喵妈70929 发布于 2023-02-06 15:48

我想知道如何从视图中删除图块.我的主要观点是这样的

我的网页的主要布局

磁贴配置由4个部分组成:标题,菜单,正文和页脚.

现在我知道如果我请求一个新页面,我可以覆盖主视图,例如替换正文,以便我在那里显示不同的内容.

但是我希望能够点击菜单中的链接,将我带到一个只有标题和正文的页面(没有菜单或页脚).

没有菜单和页脚的特定布局

然后,用户将完成一个向导,在该向导中,他们可以从一个页面转到另一个页面,然后一旦完成,它应该再次返回到主布局.

这是我的问题:如何从视图中删除菜单和页脚?我的问题在这里停止

由于没有太多关于磁贴的文档,我可以找到,我想我会为其他人努力获得使用Spring工具套件使用Apache Tiles和Spring MVC的工作示例(我的版本是STS 3.2.0).

步骤如何使用STS创建一个简单的站点

    创建一个新的STS项目

    文件>>新>> Spring模板项目>> Spring MVC Project

    选择"Spring MVC Project"选项

    为您的项目提供名称和顶级包

    GiveUrProjectANameAndPackage

    这将创建一个如下所示的项目

    在此输入图像描述

    更改POM以使用SPRING 3.2.0.RELEASE

从:

3.1.1.RELEASE

至:

3.2.0.RELEASE

    将以下依赖项添加到POM文件以包含Apache Tile依赖项



    org.apache.tiles
    tiles-api
    3.0.1


    org.apache.tiles
    tiles-core
    3.0.1


    org.apache.tiles
    tiles-jsp
    3.0.1


    org.apache.tiles
    tiles-servlet
    3.0.1


    org.apache.tiles
    tiles-template
    3.0.1
 

    更改"servlet-context.xml"以使用TilesViewResolver而不是默认的InternalViewResolver



    
    

?



    

    添加引用以了解磁贴的配置位置


     

    现在指定视图 - 用于指定视图的JSP文件...例如标题,菜单,页脚和正文(这可以是实际内容,通常您将拥有多于1个正文,具体取决于用户点击的内容菜单) - 布局将像这篇文章中的第一张图片.

在视图文件夹中创建的JSP文件各有内容

header.jsp中

This is the header

footer.jsp中

This is the footer

content1.jsp

This is content page 1

Blah blah content 1

content2.jsp

This is content page 2

Blah blah content 2

引入了menu.jsp

Menu

Go to home page
Display page 1
Display page 2

    项目创建后,它会创建一个名为"HomeController.java"的默认控制器.这是用于确定单击菜单项时下一步的位置.如果您打开家庭控制器并将其更改为以下内容

package com.stp.myapp;
import java.util.Locale;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
    /**
     * The request mapping has a value. That is what we are 
* requesting for. When opening the site it will request the main 
* page or the index page. The “/” indicates it is the index page.
* In this simple example we simply return the new ModalAndView with 
* the page in the view folder. In This case it is the mainPage.
* The mainPage is the reference of what is configured in the 
* apache tiles configuration – not the actual page that will be 
* displayed. 
     */
        @RequestMapping(value = "/", method = RequestMethod.GET)
        public ModelAndView home(Locale locale, Model model) {
        return new ModelAndView("mainPage");
        }

        /**
         * The request mapping is for page1 (page1 is the value from the menu.
         */

        @RequestMapping(value = "/page1", method = RequestMethod.GET)
        public ModelAndView viewArticle(Locale locale, Model model) {
        return new ModelAndView("displayPageContent1");
        }

        @RequestMapping(value = "/page2", method = RequestMethod.GET)
        public ModelAndView viewEmployees(Locale locale, Model model) {
        return new ModelAndView("displayPageContent2");
    }

}

    现在让我们配置磁贴

使用创建"tiles.xml"文件

 
    




    
    
        
        
        
        
        
    

     
    
    
    
    
        
        
    

    
        
        
    

     
        
        
    


tiles.xml文件具有定义为基本定义的"mainTemplate.jsp".创建一个具有主html布局的文件"mainTemplate.jsp".这些文件有"tiles:insertAttribute",它定义了可以在每个视图中覆盖的基本布局的各个部分.

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>





    <tiles:insertAttribute name="title" ignore="true"></tiles:insertAttribute>



    最后,你应该得到一个看起来像这样的文件结构

InTheEndTheFilesShouldLookLikeThis

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有