MyBatis 如何设置别名

将org.ec.entity.Student的别名设置成a,这样每次使用org.ec.entity.Student的时候使用a就更简便了。

<insert id="insertStudent" parameterType="org.ec.entity.Student">
		insert into studentMybatis(stuNo,stuName,stuAge)
		values(#{stuNo},#{stuName},#{stuAge})
</insert>

别名都在config.xml文件中设置,别名设置后在mapper.xml文件中使用忽略大小写。
1、设置单个别名

//config.xml
<configuration>
	<!-- 设置单个/多个别名 -->
	<typeAliases>
		<!-- 单个别名 -->
		<typeAlias type="org.ec.entity.Student" alias="Student"/>
	</typeAliases>
	...
	...
</configuration>
//mapper.xml
<select id="selectAllStudent" resultType="Student">//student中的字母可大写可小写,(STudent...)
	select * from studentMybatis
	</select>

2、批量设置别名
自动将该包中的所有类批量定义别名,别名就是类名(不带包路径名的类名)。

//config.xml
<configuration>
<typeAliases>
		<!-- 批量定义别名 -->
		<package name="org.ec.entity"/>
	</typeAliases>
	...
	...
</configuration>
<select id="selectAllStudent" resultType="sTuDent">//忽略大小写
	select * from studentMybatis
	</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值