java mapper xml 参数_Mybatis 文档篇 3.4:Mapper XML 之 Parameters

2 Parameters

2.1 简单参数

Parameters are very powerful elements in MyBatis. For simple situations, probably 90% of the cases, there's not much to them。

Parameters 是 MyBatis 中非常强大的元素。在简单使用中,90%的情况下参数都很少。

select id, username, password

from users

where id = #{id}

The example above demonstrates a very simple named parameter mapping.The parameterType is set to int, so therefore the parameter could be named anything.

上面的例子描述了一个非常简单的命名参数映射。parameterType 被设置为 int,因此参数可以随意命名。

Primitive or simple data types such as Integer and String have no relevant properties, and thus will replace the full value of the parameter entirely. However, if you pass in a complex object, then the behavior is a little different.

原生类型或简单的数据类型,比如 Integer 和 String,是没有关联属性的,因此它会完全用参数值来替代。但是,如果你传入的是一个复杂的对象,那么情况就不太一样。

insert into users (id, username, password)

values (#{id}, #{username}, #{password})

If a parameter object of type User was passed into that statement, the id, username and password property would be looked up and their values passed to a PreparedStatement parameter.

如果一个 User 类型的对象参数被传入这个语句,那么 id、username 和 password 属性会被查

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值