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

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

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

    風人園

    弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
    隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
    數據加載中……

    iBatis Java Mapper--A iBatis+Spring擴展 (ZT)


    轉載自 http://m.tkk7.com/xmatthew/archive/2009/01/05/249986.html

    iBatis Java Mapper是iBatis+Spring的一個擴展,能夠讓你使用Java類和接口來代替用于object-SQL映射的XML文檔。

    官方網址:http://javamapper.sourceforge.net/
    目前還沒有正式發布版本,但很值得期待。

    下面是一個示例:

    第一步把iBatis Java Mapper實現類,配置到Spring容器中。如下:
    @ResultMap {
    public class Account {

            
    private String username;
            
    private String email;

            @Result(column
    ="userid", groupBy=true)
            
    public String getUsername();
            
            @Result(column
    ="email")
            
    public String getEmail();
            
            
    // Setters 
    }


    更多示例:

    Creating Mapped Statements

    iBatis Java Mapper uses methods to map statements. Statement methods can be in classes and interfaces with or without the @ResultMap annotation, it doesn't matter. Methods are used for statement mapping if they are annotated with @Select, @Insert, @Update or @Delete.

    Here is an example of a mapped select statement:

    @Select("select username as value from signon")

    public abstract String getUsernameList();

    In this case the SQL is provided as the value of the @Select annotation. It is also possible to use a properties file to hold the SQL if you don't want it in the Java source. The properties file's path and name must match the class/interface full name, for example if the class containing the mapper method is named foo.bar.MapperClass , then its matching properties file must be /foo/bar/MapperClass.properties。The entry key is the method name and the entry value is the SQL:

    getUsernameList = select username as value from signon

    Now we can write the annotation without the SQL:

    @Select
    public abstract String getUsernameList();

    Let's take a look at the method signiture and see what iBatis Java Mapper can learn from it about the required mapping. The return type is String , so this is the class which is used as the statement result class. Now let's look at another example:

    @Select(resultClassMapper=AccountMapper.class)
    public abstract Account getAccountByUsernameAndPassword(Account account);

    Here the annotation specifies the class that contains the result map definition. In this case the return value is ignored, but we left it as sort of self-documenting code. This method also has an argument of type Account , so Account is used as parameterClass. If a method has more than one argument, iBatis Java Mapper uses the first one as parameter class and ignores the rest.

    Mapping of insert, update and delete statements is similar and even a little simpler. Here are some examples:

    @Insert
    public abstract void insertProfile(Account account);

    @Update
    public abstract void updateProfile(Account account);

    @Delete
    public abstract void deleteProfile(Account account);



    posted on 2009-04-15 16:46 風人園 閱讀(381) 評論(0)  編輯  收藏 所屬分類: Open Source

    主站蜘蛛池模板: 免费人成年轻人电影| 国产精品成人免费一区二区| 亚洲美女视频一区| 三年片免费观看大全国语| 精品无码人妻一区二区免费蜜桃| 国产AⅤ无码专区亚洲AV| WWW免费视频在线观看播放| 亚洲一区爱区精品无码| 亚洲kkk4444在线观看| 免费做爰猛烈吃奶摸视频在线观看| 亚洲免费中文字幕| 成年午夜视频免费观看视频| 亚洲精品乱码久久久久蜜桃| 免费中文字幕一级毛片| 成人免费夜片在线观看| 亚洲人成色7777在线观看| 亚洲a一级免费视频| 亚洲白色白色在线播放| 影音先锋在线免费观看| 免费一级特黄特色大片| 亚洲欧洲日产国码av系列天堂| 国产成人免费视频| 亚洲中文字幕在线乱码| 亚洲欧洲免费视频| 在线亚洲午夜片AV大片| 四虎永久在线免费观看| 拍拍拍无挡视频免费观看1000 | 波多野结衣中文一区二区免费| 黄网站色视频免费观看45分钟| 国产亚洲一区区二区在线| 中文字幕成人免费视频| 亚洲精品美女久久久久久久| 亚洲片一区二区三区| 51视频精品全部免费最新| 亚洲乱亚洲乱妇24p| 亚洲午夜无码久久久久| 永久看日本大片免费35分钟| 国内成人精品亚洲日本语音| 青青草国产免费久久久下载| 亚洲а∨天堂久久精品9966| 国产成人麻豆亚洲综合无码精品|