java 自定义比较 bean用法_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java 自定义比较 bean用法

java 自定义比较 bean用法

 2011/11/9 8:27:07  a729812804  http://a729812804.iteye.com  我要评论(0)
  • 摘要:jsp部分<s:beanid="optionComparator"name="com.cqa.util.QuestionComparator"/><s:sortcomparator="optionComparator"source="memberQuestion.MemberQuestionAnswers"><s:iterator><tralign="left"><thnowrap="nowrap">回答会员编号:</th>
  • 标签:用法 Java 自定义

jsp部分? ?



<s:bean id="optionComparator"
?? ??? ??? ??? ??? ??? ??? ?name="com.cqa.util.QuestionComparator" />
?? ??? ??? ??? ??? ??? ?<s:sort comparator="optionComparator"
?? ??? ??? ??? ??? ??? ??? ?source="memberQuestion.MemberQuestionAnswers">
?? ??? ??? ??? ??? ??? ??? ?<s:iterator>
?? ??? ??? ??? ??? ??? ??? ??? ?<tr align="left">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?回答会员编号:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="text" name="memberNo" id="memberNo"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?readonly="readonly"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?value="<s:property value="member.memberNo" />">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?问题或回答:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="text" name="askOrAnswer" id="askOrAnswer"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?readonly="readonly"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?value="<s:if test="askOrAnswer==1">问题</s:if><s:else>回答</s:else>">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ?</tr>
?? ??? ??? ??? ??? ??? ??? ??? ?<s:if test="askOrAnswer!=1">
?? ??? ??? ??? ??? ??? ??? ??? ?<tr align="left">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?专家姓名:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td width="16%">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="text" name="answerTime" id="answerTime"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?readonly="readonly"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?value="<s:property value='expert.name' />">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?回答日期:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="text" name="answerTime" id="answerTime"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?readonly="readonly"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?value="<s:date name="answerTime" format="yyyy-MM-dd" />">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ?</tr>
?? ??? ??? ??? ??? ??? ??? ??? ?</s:if>
?? ??? ??? ??? ??? ??? ??? ??? ?<tr align="left">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?是否最佳答案:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="text" name="bestAnswer" id="bestAnswer"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?readonly="readonly"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?value="<s:if test='bestAnswer==1'>是</s:if><s:elseif test='bestAnswer==0'>否</s:elseif><s:else>空</s:else>">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<input type="button" name=""onclick="doEdit(<s:property value='memberQuestionAnswerId'/>);" value="修改答案"/>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th><s:if test="askOrAnswer!=1">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td><!-- <input type="button" name=""onclick="doDelete(<s:property value='memberQuestionAnswerId'/>,<s:property value="memberQuestion.memberQuestionId" />);" value="删除此答案"/> -->
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td></s:if>
?? ??? ??? ??? ??? ??? ??? ??? ?<tr />
?? ??? ??? ??? ??? ??? ??? ??? ?<tr align="left">
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<th nowrap="nowrap">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?回答内容:
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</th>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?<td colspan="4" valign="top">
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?<textarea cols="4" rows="5" name="answerContent"
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?id="answerContent" style="width: 400px" readonly="readonly" /><s:property value="answerContent" escape="true" />
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</textarea>
?? ??? ??? ??? ??? ??? ??? ??? ??? ?</td>
?? ??? ??? ??? ??? ??? ??? ??? ?</tr>
?? ??? ??? ??? ??? ??? ??? ?</s:iterator>
?? ??? ??? ??? ??? ??? ?</s:sort>




java类部分


package com.cqa.util;

import java.util.Comparator;
import java.util.Date;

import com.cqa.pojo.MemberQuestionAnswer;

public class QuestionComparator implements Comparator {
?? ?public int compare(Object element1, Object element2) {
?? ??? ?MemberQuestionAnswer eo1 = (MemberQuestionAnswer) element1;
?? ??? ?MemberQuestionAnswer eo2 = (MemberQuestionAnswer) element2;
?? ??? ?Date s1 = eo1.getAnswerTime();
?? ??? ?Date s2 = eo2.getAnswerTime();
?? ??? ?if (s1 == null) {
?? ??? ??? ?s1 = null;
?? ??? ?}
?? ??? ?if (s2 == null) {
?? ??? ??? ?s2 = null;
?? ??? ?}
?? ??? ?return s2.compareTo(s1);
?? ?}
}

发表评论
用户名: 匿名