美文网首页
mybatis 各种注解备注

mybatis 各种注解备注

作者: felix_feng | 来源:发表于2016-12-29 08:57 被阅读102次

    @SelectProvider
    @UpdateProvider
    @InsertProvider
    @DeleteProvider
    example:

    public interface UserMapper {
        @SelectProvider(type = SqlProvider.class, method = "selectUser")
        @ResultMap("userMap")
         public User getUser(long userId);
    
         public class SqlProvider {
            public String selectUser(long userId) {
              return "select * from user where userId=" + userId;
            }
        }  
    }
    

    但是,如果在getUser方法中,对userId方法使用了@Param注解的话,那么相应selectUser方法必须接受Map<String, Object>做为参数:

    @SelectProvider(type = SqlProvider.class, method = "selectUser2")
         @ResultMap("userMap")
         public User getUser2(@Param("userId") long userId);
    
    
     public String selectUser2(Map<String, Object> para) {
             return "select * from user where userId=" + para.get("userId");
      }
    

    相关文章

      网友评论

          本文标题:mybatis 各种注解备注

          本文链接:https://www.haomeiwen.com/subject/utmuvttx.html