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 中设置的键名相匹配。

相关推荐
andongni2038 小时前
后端参数校验
spring boot·后端·mybatis
LitchiCheng1 天前
还在改xml调相机?MuJoCo交互式可视化调整相机安装位置
xml·数码相机
Devin~Y1 天前
从内容社区到AI智能客服:Spring Boot + Spring Cloud + Spring AI 全栈实战面试拆解
java·spring boot·redis·elasticsearch·spring cloud·kafka·mybatis
richard_yuu1 天前
JSON vs XML vs 二进制:3种序列化终极选型
xml·c++·qt·学习·json
丶意冷2 天前
OceanBase 双模式识别与 MyBatis-Plus 分页方言自动切换实战
mybatis·oceanbase
lv__pf2 天前
spring之整合mybatis【TL spring 12】
mysql·spring·mybatis
ChaHae-In3 天前
MyBatis动态SQL与MyBatis-Plus高效开发指南
数据库·oracle·mybatis
秋田君3 天前
QT_XML文件操作
xml·数据库·qt
counting money3 天前
Tomcat 专题:从基础架构到性能调优与 WebSocket 实战
java·websocket·tomcat
csdn2015_3 天前
springboot +mybatis 查询myql开启程序级别缓存
spring boot·缓存·mybatis