zoukankan      html  css  js  c++  java
  • mybatis12 Usermapper.xml

    输入和输出映射
    通过parameterType完成输入映射,通过resultType和resultMap完成输出映射。
    
    1.1parameterType传递pojo包装对象
    可以定义pojo包装类型扩展mapper接口输入参数的内容。
    
    需求:
    自定义查询条件查询用户信息,需要向statement输入查询条件,查询条件可以有user信息、商品信息。。。。
    
    1.1.1包装类型

     

    1.1.1mapper.xml

     

    1.1.1Mapper.java接口

    测试

    异常
    如果parameterType中指定属性错误,异常,找不到getter方法:
    
    org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userCusto' in 'class cn.itcast.mybatis.po.UserQueryVo'
    ### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userCusto' in 'class cn.itcast.mybatis.po.UserQueryVo'
        
    
    注意:如果将来和spring整合后,不是通过调用getter方法来获取属性值,通过反射强读取pojo的属性值。
    1.1resultType
    指定输出结果的类型(pojo、简单类型、hashmap..),将sql查询结果映射为java对象 。
    
    1.1.1返回简单类型
    mapper.xml

    mapper.java

    注意:
    如果查询记录结果集为一条记录且一列再使用返回简单类型。
  • 相关阅读:
    LeetCode 121. Best Time to Buy and Sell Stock
    LeetCode 221. Maximal Square
    LeetCode 152. Maximum Product Subarray
    LeetCode 53. Maximum Subarray
    LeetCode 91. Decode Ways
    LeetCode 64. Minimum Path Sum
    LeetCode 264. Ugly Number II
    LeetCode 263. Ugly Number
    LeetCode 50. Pow(x, n)
    LeetCode 279. Perfect Squares
  • 原文地址:https://www.cnblogs.com/yaowen/p/4869654.html
Copyright © 2011-2022 走看看