mybatis中xml接收参数值

你可以在 XML 映射文件中使用不同的参数占位符来接收这两个值。以下是一个示例:

xml 复制代码
<mapper namespace="com.example.mapper.UserMapper">  
    <select id="getUserByAttributes" parameterType="map" resultType="com.example.model.User">  
        SELECT * FROM user WHERE advertiser_id = #{advertiserId} AND product_platform_id = #{productPlatformId}  
    </select>  
</mapper>

在上面的示例中,我们使用了 parameterType="map",这意味着 MyBatis 将传递一个 Map 对象作为参数。在 Java 代码中,你可以创建一个 Map 对象来传递两个不同类型值的参数,如下所示:

java 复制代码
Map<String, Object> attributes = new HashMap<>();  
attributes.put("advertiserId", "someAdvertiserId");  
attributes.put("productPlatformId", "someProductPlatformId");  
  
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);  
User user = userMapper.getUserByAttributes(attributes);

在 XML 映射文件中,你可以使用 #{advertiserId} 和 #{productPlatformId} 来引用传递的 Map 对象中的属性。注意,键名(例如 advertiserId 和 productPlatformId)应该与你在 Map 中设置的键名相匹配。

相关推荐
代码什么用2 天前
使用javassist生成类 && MyBatis中接口代理机制及使用
mybatis
paopaokaka_luck2 天前
非遗文物数字化小程序(AI非遗问答、ONNX图像识别、协同过滤推荐、ECharts数据分析、非遗知识浏览与互动、文创商城订单闭环、文化活动报名签到、社区交流)
javascript·spring boot·mysql·数据分析·echarts·mybatis
韩曙亮2 天前
【JavaEE】MyBatis 基本用法 ⑤ ( 单条件查询 | 多条件查询 | 多条件动态查询 | 单条件动态查询 )
java·sql·java-ee·mybatis·mapper·sql映射
x-Achan2 天前
Redis实现方案:更新策略、穿透、雪崩、击穿、工具封装
java·spring boot·redis·spring·bootstrap·mybatis
泡海椒3 天前
JQuick-Excel JQuickRow 数据准备实战:JObjectConverter、JQuickRow.toRows 与 XML 导出链路
xml·windows·excel
shuoshuohaohao3 天前
MyBatis 小知识点
java·spring·mybatis
CarIise5 天前
MyBatis动态SQL:从条件拼接到底层原理实战
mybatis
CarIise5 天前
Spring Boot图片展示与统一返回格式:从资源映射到泛型封装实战
mybatis
泡海椒5 天前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel
钝挫力PROGRAMER5 天前
开发踩坑记:MyBatis selectKey、空 SQL
数据库·sql·mybatis