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

注意:
如果查询记录结果集为一条记录且一列再使用返回简单类型。

 

posted @ 2015-10-11 17:49  无天666  阅读(670)  评论(0编辑  收藏  举报