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

    注意:
    如果查询记录结果集为一条记录且一列再使用返回简单类型。
  • 相关阅读:
    WAMP环境下访问PHP提示下载PHP文件
    安装CMS遇到php5.3的问题
    Win2003打不开https的问题
    查看服务器硬件信息
    添加删除程序无法安装IIS 提示没法加载模块
    Spring Autowiring by AutoDetect
    Spring Autowiring by Constructor
    Spring Autowiring by Name
    Spring Autowiring by Type
    Spring Auto-Wiring Beans
  • 原文地址:https://www.cnblogs.com/yaowen/p/4869654.html
Copyright © 2011-2022 走看看