zoukankan      html  css  js  c++  java
  • tiles瓦片(小框架)技术

    一、Spring中配置tiles配置

      

    <!-- 普通视图解析器视图解析器 -->
    	
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/"></property>
    		<property name="suffix" value=".jsp"></property>
    		<property name="order" value="2"></property>
    	</bean>
    	
    	<!-- tiles视图解析器 -->
    	
    	<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="urlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></property>
    		<property name="order" value="1"></property>
    	</bean>
    	
    	
    	<!-- 加载tiles瓦片 -->
    	
    	<bean class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" id="tilesConfigurer">
    		<property name="definitions">
    			<list>
    				<value>/WEB-INF/tiles.xml</value>
    			</list>
    		</property>
    	</bean>
    

      二、tiles.xml的配置

    <tiles-definitions>
      	<!-- 定义一个模板 -->
      <definition name="layout" template="/view/index.jsp">
      		<put-attribute name="top" value="/view/laway/top.jsp"></put-attribute>
      		<put-attribute name="left" value="/view/laway/left.jsp"></put-attribute>
      		<put-attribute name="foot" value="/view/laway/foot.jsp"></put-attribute>
      </definition>
      
      
     <!-- 又定义了N个视图  控制器返回视图: sale/lookstore      -->
      <definition name="salay/*" extends="layout">
      		<put-attribute name="right" value="/view/salay/{1}.jsp"></put-attribute>
      </definition>
      
      
      
    </tiles-definitions>
    

      说明 name为返回视图的路径

    三、页面分层布局(即用下图的foot.jsp、left.jsp、top.jsp合成一个完整的页面)

      

    foot,jsp书写如下(直接写标签就可以了)

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <h1>尾部</h1>
    

      index.jsp书写如下

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
    
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        
        
        <title>My JSP 'index.jsp' starting page</title>
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    	
    	<style type="text/css">
    		.div1{
    			float: left;
    			 200px;
    			height: 500px;
    			border: 1px solid red;
    		}
    		
    		.div2{
    		 10 00px;
    		height: 500px;
    		border: 1px solid red;
    		
    		}
    	
    	</style>
      </head>
      
      <body>
        
        <div>
        	<tiles:insertAttribute name="top"></tiles:insertAttribute>
        </div>
        
        <div>
        	<div class="div1">
        		<tiles:insertAttribute name="left"></tiles:insertAttribute>
        	</div>
        	
        	<div class="div2">
        	<tiles:insertAttribute name="right"></tiles:insertAttribute>
        	
        	</div>
        
        </div>
        
        <div > 
        	<tiles:insertAttribute name="foot"></tiles:insertAttribute>
        </div>
        
        
        
      </body>
    </html>
    

      四、controller的书写

    package com.exam.story.controller;

    import javax.servlet.http.HttpServletRequest;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    public class ExamController {
    @RequestMapping("sala")
    public String sala(){
    return "salay/sala";
    }

    @RequestMapping("salaInfo")
    public String salaInfo(){
    return "salay/salaInfo";
    }

    @RequestMapping("salaStore")
    public String salaStore(HttpServletRequest request){
    return "salay/salaStore";
    }

    @RequestMapping("goIndex")
    public String goIndex(){
    return "salay/sala";
    }
    }

    界面效果如下:

  • 相关阅读:
    ASP.NET MVC深入浅出(被替换)
    第十七节: EF的CodeFirst模式的四种初始化策略和通过Migration进行数据的迁移
    第十六节: EF的CodeFirst模式通过Fluent API修改默认协定
    第十五节: EF的CodeFirst模式通过DataAnnotations修改默认协定
    第十四节: EF的三种模式(四) 之 原生正宗的 CodeFirst模式的默认约定
    第十三节: EF的三种模式(三) 之 来自数据库的CodeFirst模式
    C#读写记事本(txt)文件
    JSP生成验证码
    SQLServer创建用户、数据库、表、约束、存储过程、视图
    windows7 asp.net发布IIS 拒绝访问 解决方法
  • 原文地址:https://www.cnblogs.com/story1/p/8245388.html
Copyright © 2011-2022 走看看