MyBatis 总配置中 typeAliases 详解
时间:2022-05-27 22:07:25
收藏:0
阅读:9
1.介绍
在Mybatis中的sql语句映射的时候会使用paramterType,和resultType来设置sql语句的参数(返回值类型,或者路径等等)
这些都是需要声明全路径的,就比如 paramterType=“com.atguigu.mybatis.pojo.Person”,这样有点麻烦,使用typeAliAses来设置别名降低复杂度
2.代码示例
<insert id="addPerson" parameterType="com.aoligei.mybatis.pojo.Person"> insert into t_person values(0,#{pname},#{address}) </insert>
当设置 MyBatis 的总配置文件 mybatis-Config 中的 typeAliases 属性后,就可以为 sql 映射文件中的输入 / 输出参数设置类型别名,然后在 sql 映射配置文件中指定输入输出参数类型时使用的别名。
示例如下:
<typeAliases>
<package name="com.atguigu.mybatis.pojo"/>
</typeAliases>
这样就可以直接在映射的配置文件中使用别名了
<insert id="addPerson" parameterType="Person"> insert into t_person values(0,#{pname},#{address}) </insert>
暂时就这些,百度了看别的大佬说好像还有别的,暂时没学习到,学到了在更新
原文:https://www.cnblogs.com/xuanshi/p/15354523.html
评论(0)