posts - 156,  comments - 601,  trackbacks - 0
          iBatis Java Mapper是iBatis+Spring的一個擴(kuò)展,能夠讓你使用Java類和接口來代替用于object-SQL映射的XML文檔。

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

          下面是一個示例:

          第一步把iBatis Java Mapper實現(xiàn)類,配置到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);




          Good Luck!
          Yours Matthew!
          posted on 2009-01-05 21:35 x.matthew 閱讀(2813) 評論(0)  編輯  收藏 所屬分類: 最新開源動態(tài)
          主站蜘蛛池模板: 盖州市| 教育| 阿合奇县| 同心县| 融水| 太保市| 临潭县| 常宁市| 嘉峪关市| 青冈县| 酉阳| 杭锦后旗| 高台县| 长子县| 罗山县| 育儿| 曲阳县| 奉节县| 万荣县| 城口县| 阜南县| 桂东县| 高唐县| 山东省| 富裕县| 屏东市| 泸州市| 北安市| 西和县| 潜江市| 宁海县| 扎赉特旗| 兴义市| 旅游| 临朐县| 剑河县| 咸阳市| 砀山县| 常德市| 确山县| 英吉沙县|