Mybatis 中resultMap,resultType区别
基本映射 :(resultType)使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功。(数据库,实体,查询字段,,这些全部都得一一对应)
高级映射 :(resultMap) 如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间作一个映射关系。(高级映射,字段名称可以不一致,通过映射来实现)
参考:https://www.cnblogs.com/Darkqueen/p/10682039.html
MyBatis中如何表示Decimal
使用java.math.BigDecimal
MyBatis中多个参数时,如何自定义变量名
使用@param 基于注解来指定 ,把可以把封闭到map中,用#{keyname}来表示
String getXXXByUserIdAndExamId(@Param("userId") Integer userId, @Param("examId") Integer examId);
MyBatis中如何插入多行
参数传入list,里面有foreach进
int addRItem(@Param(value = "list") List<GreenBeanMsg> list);
<insert id="addRItem" parameterType="java.util.List">
insert into lzf_rental_item_detailsl
(
id,
rentalInfoId,
itemName,
number,
remark
)
values
<foreach collection="list" item="item" index= "index" separator =",">
(
#{item.id},
#{item.rentalInfoId},
#{item.itemName},
#{item.number},
#{item.remark}
)
</foreach>
</insert>
Mybatis中多个参数时,有String又有List时如何传
将String和List放入map中,再对map中的list进行遍历
List<String> list = new ArrayList<String>();
Map<String, Object> map = new HashMap<String, Object>();
list.add("1");
list.add("2");
map.put("list", list);
map.put("str", "0");
Mybatis中如何继承原有的类
使用extends 来继承原有的,通常是在原有的实体中增加自定义的列。这样就不用再重新写原来的属性了。
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.caiyun.entity.TblGpExam">
<result column="rule" jdbcType="LONGVARCHAR" property="rule" />
</resultMap>
Mybatis报错nested exception
xxx.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file
检查xxx.xml中,看是不是有指定的类型转化错误 ,一定是在这个文件中哪里设置的不对,仔细检查排除。
MyBatis报No enum constant org.apache.ibatis.type.JdbcType.String
查看xml中字段的类型,通过是对应的类型设置错误 。
《美好的一天》剧情片高清在线免费观看:https://www.jgz518.com/xingkong/107.html
这篇文章提供了宝贵的经验和见解,对读者有很大的启发和帮助。