黑马程序员:struts2 获取一对多关系的对象的对象的属性

------- android培训 java培训、期待与您交流!-------




struts2 获取一对多关系的对象的对象的属性
http://blog.sina.com.cn/s/blog_67b9ad8d0100yat1.html
http://tiger-hu.iteye.com/blog/1032623

通过下面的JSP代码可以发现,一些等价关系:
//取对象时
<s:iterator value="#request.allPatient" id="patient">
	<s:property value="id"/> 与 ${patient.id} 等价

	   ${patient.person.id} 与	<s:property value="#patient.person.id"/>等价 与${person.id}等价
</s:iterator>



<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page isELIgnored="false" %> 
<%
String path = request.getContextPath();
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<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="<%=path %>/css/base.css" />
		<script type="text/javascript" src="<%=path %>/js/public.js"></script>
		<script type="text/javascript" src="<%=path %>/My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="<%=path %>/js/popup.js"></script>
        <script language="javascript">
           function patientDelete(id)
           {
               if(confirm('您确定删除吗?'))
               {
                   window.location.href="<%=path %>/patient/Patient-delete?id="+id;
               }
           }
           
           function patientAdd()
           {
                 var url="<%=path %>Patient-add.jsp";
				 window.location.href=url;
           }
       </script>
	</head>
<body leftmargin="2" topmargin="2" background='<%=path %>/images/allbg.gif'>
<center>
	<h2>用户列表</h2>
	<table border="1">
		
		<tr>
			<td>个人ID</td>
			<td>病人ID</td>
			<td>用户名</td>
			<td>挂号单时间</td>	
			<td>就诊科目</td>
			<td>主诉</td>
			<td>诊断</td>
			<td>费用</td>		
		</tr>
		<s:iterator value="#request.allPatient" id="patient">
		<tr>
			<td><a href="Person-showPerson?id=<s:property value='#patient.person_id'/>"><s:property value="#patient.person_id"/></a></td>
			<td><a href="Patient-showPatient?id=<s:property value='#patient.id'/>"><s:property value="#patient.id"/></a></td>
			<td><s:property value="#"/></td>
			<td><s:property value="#patient.datetime"/></td>	
			<td><s:property value="#patient.subject"/></td>
			<td><a href="Patient-delete?id=<s:property value='#patient.id'/>">删除挂号单</a></td>
			<td><a href="Patient-update.jsp?id=<s:property value='#patient.id'/>">更新挂号单</a></td>	
		</tr>
		</s:iterator>	
	</table>
	
	<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
				<tr bgcolor="#E7E7E7">
					<td height="14" colspan="18" background="<%=path %>/images/tbg.gif">&nbsp;病人挂号信息管理&nbsp;</td>
				</tr>
				<tr align="center" bgcolor="#FAFAF1" height="22">
					<td >个人ID</td>
					<td ">病人ID</td>
					<td ">用户名</td>
					<td ">挂号单时间</td>
					
					<td ">就诊科目</td>
					<td ">主诉</td>
					<td ">诊断</td>
					<td ">费用</td>
					
					
					
					
					<td ">修改</td>
					<td ">删除</td>
		        </tr>	
				<s:iterator value="#request.allPatient" id="patient">
				<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='red';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
					<td bgcolor="#FFFFFF" align="center">
						<s:property value="id"/>
					</td>
					<td bgcolor="#FFFFFF" align="center">
					   <s:property value="person.id"/>
					</td>
					<td bgcolor="#FFFFFF" align="center">
					 	<s:property value="person.name"/>
					</td>
					<td bgcolor="#FFFFFF" align="center">
					 	<s:property value="datetime"/>
					</td>
					<td bgcolor="#FFFFFF" align="center">
						<s:property value="subject"/>
					</td>
				    <td bgcolor="#FFFFFF" align="center">
					   <s:property value="expatiate"/>
					</td>
					<td bgcolor="#FFFFFF" align="center">
					    <s:property value="diagnose"/>
					</td>
					
					<td bgcolor="#FFFFFF" align="center">
					  <s:property value="price"/>
					</td>

					
					<td bgcolor="#FFFFFF" align="center">
					    6
					</td>
					<td bgcolor="#FFFFFF" align="center">
						<form action="" name="formAdd" method="post">
						   <input type="button" value="删除" onclick="patientDelete(${patient.id})"/>
						</form>
					</td>
				</tr>
				</s:iterator>
			</table>
	
	<a href="Patient-add.jsp">添加新挂号单</a>		
	<s:debug id="2"/>
</center>
</body>
</html>

------- android培训 java培训、期待与您交流!-------


详细请查看: http://edu.csdn.net/heima -------

你可能感兴趣的:(struts2)