集合的排序

来源:互联网 发布:php支持mysql扩展 编辑:程序博客网 时间:2024/05/17 22:44

对Set集合的排序,使用Java方式

代碼:

<set name="addrs" table="ADDRS" sort="natural">
        <key column="USER_ID"/>
        <element type="string" column="ADDRESS" not-null="true"/>
</set>



代碼:

<map name="files" table="FILES" sort="natural">
    <key column="USER_ID"/>
    <index column="DESCRIPTION" type="string"/>
    <element type="string" column="FILENAME" not-null="true"/>
</map>



,sort除了natural之外,也可以指定一个实现java.util.Comparator的类名。

使用Sql语句进行排序

代碼:

<set name="addrs" table="ADDRS" order-by="ADDRESS desc">
        <key column="USER_ID"/>
        <element type="string" column="ADDRESS" not-null="true"/>
</set>



在Map中也是相同的設定方式,您也可以利用資料庫中的函式功能,例如:

代碼:

<map name="files" table="FILES" order-by="lower(FILENAME)">
    <key column="USER_ID"/>
    <index column="DESCRIPTION" type="string"/>
    <element type="string" column="FILENAME" not-null="true"/>
</map>

 

原创粉丝点击