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

    注意:
    如果查询记录结果集为一条记录且一列再使用返回简单类型。
  • 相关阅读:
    UI测试
    软件测试用例详解(转载)
    Mac设置命令别名
    CentOS7 开启免密登陆
    使用systemctl命令管理服务mysql
    Redis学习笔记02--主从数据库配置
    CentOS使用dnf安装Redis
    CentOS 7 防火墙设置
    Redis学习笔记01---配置文件
    CentOS7搭建Maven的Nexus私服仓库
  • 原文地址:https://www.cnblogs.com/yaowen/p/4869654.html
Copyright © 2011-2022 走看看