亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

簡單說明Java的Struts框架中merge標(biāo)簽的使用方法

 更新時(shí)間:2015年12月04日 08:49:47   投稿:goldensun  
這篇文章主要簡單介紹了Java的Struts框架中merge標(biāo)簽的使用方法,Struts是Java的SSH三大web開發(fā)框架之一,需要的朋友可以參考下

merge標(biāo)簽合并標(biāo)記需要兩個或兩個以上的列表作為參數(shù),并把它們合并在一起,如下所示:

<s:merge var="myMergedIterator">
   <s:param value="%{myList1}" />
   <s:param value="%{myList2}" />
   <s:param value="%{myList3}" />
</s:merge>
<s:iterator value="%{#myMergedIterator}">
   <s:property />
</s:iterator>

如果有兩個列表A和B的值,A1,A2和B1,B2。合并列表,會給出A1,B1,A2,B2。

創(chuàng)建動作類:
首先,讓我們創(chuàng)建一個簡單的類叫做Employee.java,它看起來像:

package com.yiibai.struts2;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.util.SubsetIteratorFilter.Decider;

public class Employee {
  private String name;
  private String department;

  public Employee(){}
  public Employee(String name,String department)
  {
   this.name = name;
   this.department = department;
  }
  private List employees;
  private List contractors;
 
  public String execute() {
   employees = new ArrayList();
   employees.add(new Employee("George","Recruitment"));
   employees.add(new Employee("Danielle","Accounts"));
   employees.add(new Employee("Melissa","Recruitment"));
   employees.add(new Employee("Rose","Accounts"));

   contractors = new ArrayList();
   contractors.add(new Employee("Mindy","Database"));
   contractors.add(new Employee("Vanessa","Network"));
   return "success";
  }

  public Decider getRecruitmentDecider() {
   return new Decider() {
     public boolean decide(Object element) throws Exception {
      Employee employee = (Employee)element;
      return employee.getDepartment().equals("Recruitment");
     }
   };
  }
  public String getName() {
   return name;
  }
  public void setName(String name) {
   this.name = name;
  }
  public String getDepartment() {
   return department;
  }
  public void setDepartment(String department) {
   this.department = department;
  }
  public List getEmployees() {
   return employees;
  }
  public void setEmployees(List employees) {
   this.employees = employees;
  }
  public List getContractors() {
   return contractors;
  }
  public void setContractors(List contractors) {
   this.contractors = contractors;
  }
 
}

Employee類有兩個屬性 - name 和 department,我們也有兩個員工名單 - employees 和contractors。我們有一個方法叫做getRecruitmentDecider,返回Decider 對象。Decider 實(shí)現(xiàn)返回true,如果雇員招聘部門工作,否則返回false。

接下來,讓我們創(chuàng)建一個DepartmentComparator 比較Employee對象:

package com.yiibai.struts2;

import java.util.Comparator;

public class DepartmentComparator implements Comparator {
  public int compare(Employee e1, Employee e2) {
   return e1.getDepartment().compareTo(e2.getDepartment());
  }

  @Override
  public int compare(Object arg0, Object arg1) {
 return 0;
 }
}

在上面的例子所示,部門比較的基礎(chǔ)上按字母順序排列的部門員工進(jìn)行比較。

創(chuàng)建視圖
創(chuàng)建一個文件叫做employee.jsp以下內(nèi)容:

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Employees</title>
</head>
<body>
  <b>Employees and Contractors Merged together</b>
  <br />
  <s:merge id="allemployees">
   <s:param value="employees" />
   <s:param value="contractors" />
  </s:merge>
  <s:iterator value="allemployees">
   <s:property value="name"/>,
   <s:property value="department"/><br/>
  </s:iterator>
</body>
</html>

合并標(biāo)記需要兩個或兩個以上的列表作為參數(shù)。我們需要給合并一個id,這樣我們就可以重用它。在這個例子中,我們提供了作為參數(shù)傳遞給員工和承包商的合并標(biāo)簽。然后,我們使用“allemployees”ID合并列表遍歷并打印員工的細(xì)節(jié)。

配置文件
struts.xml中應(yīng)該像這樣:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
  <constant name="struts.devMode" value="true" />

  <package name="helloworld" extends="struts-default">
   <action name="employee" 
     class="com.yiibai.struts2.Employee"
     method="execute">
     <result name="success">/employee.jsp</result>
   </action>
  </package>

</struts>

web.xml中,應(yīng)該像這樣:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee" 
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  id="WebApp_ID" version="3.0">
  
  <display-name>Struts 2</display-name>
  <welcome-file-list>
   <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>
     org.apache.struts2.dispatcher.FilterDispatcher
   </filter-class>
  </filter>

  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

右鍵點(diǎn)擊項(xiàng)目名稱,并單擊 Export > WAR File創(chuàng)建一個WAR文件。然后部署此WAR在Tomcat的webapps目錄下。最后,啟動Tomcat服務(wù)器和嘗試訪問URL http://localhost:8080/HelloWorldStruts2/employee.action。這會給出以下畫面:

201512484907744.jpg (560×264)

相關(guān)文章

  • JAVA JSP頁面技術(shù)之EL表達(dá)式整理歸納總結(jié)

    JAVA JSP頁面技術(shù)之EL表達(dá)式整理歸納總結(jié)

    這篇文章主要介紹了java中JSP頁面技術(shù)之EL表達(dá)式概念作用以及語法等的使用,需要的朋友可以參考
    2017-04-04
  • Spring Bean基本管理實(shí)例詳解

    Spring Bean基本管理實(shí)例詳解

    這篇文章主要介紹了Spring Bean基本管理,以實(shí)例形式較為詳細(xì)的分析了Spring Bean的相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • Spring集成Struts與Hibernate入門詳解

    Spring集成Struts與Hibernate入門詳解

    這篇文章主要給大家介紹了關(guān)于Spring集成Struts與Hibernate的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • 使用IDEA搭建一個簡單的SpringBoot項(xiàng)目超詳細(xì)過程

    使用IDEA搭建一個簡單的SpringBoot項(xiàng)目超詳細(xì)過程

    這篇文章主要介紹了使用IDEA搭建一個簡單的SpringBoot項(xiàng)目超詳細(xì)過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-02-02
  • spring boot創(chuàng)建項(xiàng)目包依賴問題的解決

    spring boot創(chuàng)建項(xiàng)目包依賴問題的解決

    本篇文章主要介紹了spring boot創(chuàng)建項(xiàng)目包依賴問題的解決,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • springboot切換使用undertow容器的方式

    springboot切換使用undertow容器的方式

    最近稍微有點(diǎn)空閑,回頭再來優(yōu)化下基礎(chǔ)框架,也是一種重新學(xué)習(xí)。今天主要寫寫跟大家分享下springboot使用undertow,廢話不多說
    2022-07-07
  • Springmvc基于fastjson實(shí)現(xiàn)導(dǎo)包及配置文件

    Springmvc基于fastjson實(shí)現(xiàn)導(dǎo)包及配置文件

    這篇文章主要介紹了Springmvc基于fastjson實(shí)現(xiàn)導(dǎo)包及配置文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Springboot編寫CRUD時(shí)訪問對應(yīng)數(shù)據(jù)函數(shù)返回null的問題及解決方法

    Springboot編寫CRUD時(shí)訪問對應(yīng)數(shù)據(jù)函數(shù)返回null的問題及解決方法

    我在學(xué)習(xí)springboot,其中在編寫CRUD時(shí)發(fā)現(xiàn)訪問數(shù)據(jù)的函數(shù)執(zhí)行下去返回值是null但是其它部分正常,這篇文章主要介紹了Springboot在編寫CRUD時(shí),訪問對應(yīng)數(shù)據(jù)函數(shù)返回null,需要的朋友可以參考下
    2024-02-02
  • SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法

    SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法

    這篇文章主要介紹了SpringBoot中使用Jsoup爬取網(wǎng)站數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • jar包打包成exe安裝包的實(shí)現(xiàn)

    jar包打包成exe安裝包的實(shí)現(xiàn)

    本文主要介紹了jar包打包成exe安裝包的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07

最新評論