mybatis如何给xml映射文件的接口传递多个参数
分类:计算机 | 数据库 | Mybatis | 综合 1218
更新:2020-12-30 09:31:48编辑
转载地址
https://blog.csdn.net/dengjili/article/details/83386612
1 map方式
当多个变量传入时候,设置入参为map类型,本质上map存储了入参的键值对。
- 优点:几乎使用所有场景
- 缺点:业务性质太差,可读性太差,必须要依赖于接口才能明白入参
<select id="getRolesByMap" parameterType="map" resultType="priv.dengjl.ns.day0001.bean.Role"> select id, name, `desc` from Role where id = #{id} and name = #{name} </select>
接口声明:
List<Role> getRolesByMap(Map parameterMap);
2 注解@Param方式
使用@Param方式,显式指出关键字,如@Param(“key_id”) int id,key_id表示id
<select id="getRolesByParam" resultType="priv.dengjl.ns.day0001.bean.Role">
select id, name, `desc` from Role where id = #{key_id} and name = #{key_name}
</select>
接口声明:
List<Role> getRolesByParam(@Param("key_id") int id, @Param("key_name") String name);
3 java bean方式
定义一个bean存储变量值
<select id="getRolesByBean" parameterType="priv.dengjl.ns.day0001.bean.Role" resultType="priv.dengjl.ns.day0001.bean.Role">
select id, name, `desc` from Role where id = #{id} and name = #{name}
</select>
接口声明:
List<Role> getRolesByBean(Role role);
猿导航
阅读排行榜
- 1vue和el-table使用经验-如何刷新表格数据10948
- 2three.js加载3D瓦片和3dtiles数据生成交互式地图的开源项目9497
- 3Microsoft Visual C++ Redistributable是什么,有什么作用?7274
- 4mybatis使用经验——mybatis-spring-boot-starter和mybatis的版本对应关系表(持续更新~)5842
- 5uni-app使用经验—vue页面和html页面如何互相调用接口并传参5480
- 6Intellij IDEA下的版本控制VCS的启用与关闭4894
- 7Spring学习经验—@ResponseBody注解的使用说明4890
- 8Druid异常解决经验—java.sql.SQLException url not set4513
- 9如何用批处理命令(bat脚本)启动和停止windows服务4282
- 10nuxt.js项目中如何添加和使用全局变量4158
- 11解决SpringBoot使用maven下载不了jar包的问题3497
- 12linux中解压tar.gz文件报错“gzip: stdin: invalid compressed data--format violated”3394
- 13nuxtjs asyncData使用经验—如何发起多个axios请求并携带参数3246
- 14在Nuxt.js项目的head中引用外部js文件3088
- 15在NVIDIA控制面板设置参数时提示“拒绝访问 无法应用选定的设置到您的系统”的解决方法之一3066