<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-57  評論-202  文章-17  trackbacks-0
          Criteria Query是很好的一種面向對象的查詢實現,它提供了一種示例查詢的方式。該方式根據已有的對象,查找數據庫中屬性匹配的其他對象。
          下面是一個場景片斷,模糊查找數據庫中用戶帳號為'test',郵件地址為'georgehill@21cn.com'的實例,忽略大小寫。

      public void testCriteriaExampleQuery() throws Exception {
        User user 
    = new User();
        user.setAccount(
    "test");
        user.setEmail(
    "georgehill@21cn.com");
        
        Criteria criteria 
    = session.createCriteria(User.class).add(Example.create(user).enableLike(MatchMode.ANYWHERE).ignoreCase());
        List list 
    = criteria.list();
        
        
    if (list != null{
          
    for (int i = 0; i < list.size(); i++{
            System.
    out.println(((User) list.get(i)).getAccount());
          }

        }

      }

          示例查詢需要生成Example實例,可以通過Example的靜態方法create生成。Example類有下面的幾個方法指定查詢的方式:

    excludeZeroes

    public Example excludeZeroes()
    Exclude zero-valued properties


    excludeNone

    public Example excludeNone()
    Don't exclude null or zero-valued properties


    enableLike

    public Example enableLike(MatchMode matchMode)
    Use the "like" operator for all string-valued properties


    enableLike

    public Example enableLike()
    Use the "like" operator for all string-valued properties


    ignoreCase

    public Example ignoreCase()
    Ignore case for all string-valued properties


    excludeProperty

    public Example excludeProperty(String name)
    Exclude a particular named property



          當用enableLike()方法時,可以通過MatchMode指定匹配的方式。MatchMode提供了四種匹配的方式:

    Field Summary
    static MatchMode ANYWHERE
              Match the pattern anywhere in the string
    static MatchMode END
              Match the end of the string to the pattern
    static MatchMode EXACT
              Match the entire string to the pattern
    static MatchMode START
              Match the start of the string to the pattern
    posted on 2005-06-03 17:27 小米 閱讀(2186) 評論(3)  編輯  收藏 所屬分類: Hibernate

    評論:
    # re: Criteria的示例查詢 2006-03-24 19:01 |
    很好,謝謝  回復  更多評論
      
    # re: Criteria的示例查詢 2007-02-11 09:26 | 高溥
    假如在表里有一個日期類型的屬性,想要查詢某個時間段的數據,該怎么辦?還是示例查詢  回復  更多評論
      
    # re: Criteria的示例查詢 2007-05-17 00:17 | yellowhat
    嗯 不錯!`  回復  更多評論
      
    主站蜘蛛池模板: 亚洲av无码无线在线观看| 夜夜春亚洲嫩草影院| 亚洲小视频在线播放| 人人玩人人添人人澡免费| 亚洲精品无码av天堂| 青草久久精品亚洲综合专区| 好大好硬好爽免费视频| 亚洲AV成人影视在线观看 | 一区二区在线视频免费观看| 免费的一级片网站| 国产区图片区小说区亚洲区| 亚洲成a人无码av波多野按摩| 美女视频黄.免费网址| 亚洲一级特黄无码片| 久久www免费人成精品香蕉| 亚洲一区二区三区四区视频| 久久国产高潮流白浆免费观看| 午夜影视日本亚洲欧洲精品一区| 国产免费一区二区视频| 在线电影你懂的亚洲| 欧美日韩国产免费一区二区三区| 亚洲最大天堂无码精品区| 国产老女人精品免费视频| 人妻免费久久久久久久了| 国产亚洲色婷婷久久99精品| 一区二区三区福利视频免费观看| 亚洲成A∨人片在线观看无码| 最近中文字幕mv手机免费高清| 国产成人人综合亚洲欧美丁香花 | 国产又黄又爽又猛免费app| 亚洲精品V天堂中文字幕| 国产精品V亚洲精品V日韩精品| 久久精品免费观看| 国产亚洲福利在线视频| 又黄又爽的视频免费看| 久久精品视频免费播放| 亚洲熟妇无码一区二区三区| 国产亚洲午夜高清国产拍精品| 久久久精品2019免费观看| 亚洲av成本人无码网站| 久久久久亚洲av无码专区蜜芽|