<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

    主站蜘蛛池模板: 巨胸喷奶水www永久免费| 亚洲国产天堂久久综合| 成人国产精品免费视频| 日本亚洲免费无线码| 久久国产亚洲精品麻豆| 免费夜色污私人影院在线观看| 3d成人免费动漫在线观看| 91免费在线视频| 国产亚洲欧美日韩亚洲中文色| 亚洲精品网站在线观看你懂的| 亚洲午夜国产精品无码| 国产大片51精品免费观看| 中文字幕无码成人免费视频| 久久久99精品免费观看| 久久久精品国产亚洲成人满18免费网站| 亚洲av成本人无码网站| 国产成人亚洲综合色影视| 免费一级毛片不卡在线播放| 午夜视频在线在免费| 成人免费激情视频| 最近免费2019中文字幕大全| 国产免费AV片在线观看| 四虎国产精品成人免费久久| 免费人成毛片动漫在线播放| 国产91成人精品亚洲精品| 亚洲熟女乱色一区二区三区| 欧洲 亚洲 国产图片综合| 亚洲乱码一区av春药高潮| 亚洲图片中文字幕| 亚洲国产中文在线二区三区免| 亚洲无删减国产精品一区| 亚洲国产高清在线| 久久久久久亚洲精品| 亚洲好看的理论片电影| 久久水蜜桃亚洲av无码精品麻豆| 亚洲精品午夜无码专区| 亚洲av之男人的天堂网站| 亚洲AV无码成人网站久久精品大 | 亚洲喷奶水中文字幕电影 | 三年片在线观看免费观看大全动漫| 中文字幕高清免费不卡视频|