Mybatis中的别名的作用

Mybatis中别名的作用:

在mybatis-config.xml配置别名如下:

<!-- 别名 -->
 <typeAliases>
  <package name="cn.itcast.core.bean"/>
 </typeAliases>

它的作用是让Mapper.xml中的参数找到对应类,如下面parameterType="TestTb">,如果没有配置别名,则要改为parameterType="cn.itcast.core.bean.TestTb">,

配置别名首先当然要保证pojo实体,在一个包下面如cn.itcast.core.bean,这样配置别名后,都可找到对应的参数;

<mapper namespace="cn.itcast.core.dao.TestTbDao">

 <!-- 保存 -->
 <insert id="insertTestTb" parameterType="TestTb">
  insert into test_tb
  (id,name,birthday)
  values
  (#{id},#{name},#{birthday})
 </insert>
 
</mapper>

猜你喜欢

转载自blog.csdn.net/qq_37922457/article/details/80039472