java 自定义比较 bean用法

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=""οnclick="doEdit(<s:property value='memberQuestionAnswerId'/>);" value="修改答案"/>
                                    </th><s:if test="askOrAnswer!=1">
                                    <td><!-- <input type="button" name=""οnclick="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);
    }
}

 

 

//控制层用到的比较方法

 

//methodLst 是List集合

 

if (CollectionUtils.isNotEmpty(methodLst)) {
            Collections.sort(methodLst, new Comparator<MethodAndStandardDto>() {
                public int compare(MethodAndStandardDto arg0,
                        MethodAndStandardDto arg1) {
                    return arg0.getMethodId().compareTo(arg1.getMethodId());
                }
            });
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值