MyBatis的Mapper.xml

1.statement 标签:select、update、delete、insert 分别对应查询、修改、删除、添加操作。

2.parameterType:参数数据类型

  • 基本数据类型,通过 id 查询 Account
在这里插入代码片 
<select id="findById" parameterType="long" resultType="com.southwind.entity.Account"> 
	select * from t_account where id = #{id}
</select>
  • String 类型,通过 name 查询 Account
<select id="findByName" parameterType="java.lang.String" resultType="com.southwind.entity.Account">
	select * from t_account where username = #{username}
</select>
  • 包装类,通过 id 查询 Account
<select id="findById2" parameterType="java.lang.Long" resultType="com.southwind.entity.Account">
	select * from t_account where id = #{id}
</select>
  • 多个参数,通过 name 和 age 查询 Account
<select id="findByNameAndAge" resultType="com.southwind.entity.Account"> 
	select * from t_account where username = #{arg0} and age = #{arg1}
</select>
  • Java Bean
<update id="update" parameterType="com.southwind.entity.Account">
	update t_account set username = #{username},password = #{password},age =#{age} where id = #{id}
</update>

3.resultType:结果类型

  • 基本数据类型,统计 Account 总数
<select id="count" resultType="int"> 
	select count(id) from t_account
</select>
  • 包装类,统计 Account 总数
<select id="count2" resultType="java.lang.Integer"> 
	select count(id) from t_account
</select>
  • String 类型,通过 id 查询 Account 的 name
<select id="findNameById" resultType="java.lang.String"> 
	select username from t_account where id = #{id}
</select>
  • Java Bean
 
<select id="findById" parameterType="long" resultType="com.southwind.entity.Account">
	select * from t_account where id = #{id}
</select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值