1.alias:主要用来自定别名
2.非自定义别名:在这个文件下什么都不配置,但是在映射文件里面比如:
用到:java.lang.Interge 可直接使用 int 该别名进行使用
mybatis-config.xml配置如下:
<!--
非自定义别名:jdk中所有类都使用了非自定义别名,别名内容是类名的所哟普字母不区分大小写
如果是包装类还可以使用其基本数据类型的名字
-->
<!--自定义别名-->
<typeAliases>
<!--type: 要被定义成别名的数据类型-->
<typeAlias type="zhou.model.Person" alias="person"/>
</typeAliases>
<!--
数据库环境配置如果和spring整合就不需要配了,完全交给spring
default:决定你要用哪个数据源
-->
映射文件(根据alias定义的别名进行使用):
<update id="update" parameterType="person">
update person_test t set
t.name = #{name},
t.gender = #{gender},
t.address = #{address},
t.birthday = #{birthday}
where
t.id = #{id}
</update>
<delete id="delete" parameterType="person">
delete from person_test where id = #{id}
</delete>
非自定义别名(parameterType属性的值):
<select id="selectPersonById" parameterType="int" resultType="person">
select * from person_test where id = #{id}
</select>
3.sql片段映射文件配置:
<!--提取出来一些公用的sql片段,公用-->
<sql id="colums">
id, `name`, gender, address, birthday
</sql>
使用方式:
<select id="selectPersonById" parameterType="int" resultType="person">
select <include refid="colums"/> from person_test where id = #{id}
</select>