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

相关推荐
哈库纳玛塔塔3 小时前
公元前日期处理的两种方案
数据库·算法·mybatis
MX_93597 小时前
Spring注解方式整合Mybatis
java·后端·spring·mybatis
shsh20018 小时前
mybatis plus打印sql日志
数据库·sql·mybatis
文艺倾年1 天前
【源码精讲+简历包装】LeetcodeRunner—手搓调试器轮子(20W字-上)
java·jvm·人工智能·tomcat·编辑器·guava
e***13621 天前
linux 设置tomcat开机启动
linux·运维·tomcat
草履虫建模1 天前
Java面试应对思路和题库
java·jvm·spring boot·分布式·spring cloud·面试·mybatis
Forget_85501 天前
RHEL——web应用服务器TOMCAT
java·前端·tomcat
Hx_Ma161 天前
Springboot整合mybatis配置文件
spring boot·后端·mybatis
手握风云-1 天前
JavaEE 进阶第十九期:MyBatis-Plus,让 CRUD 飞起来
java·java-ee·mybatis
nnbulls11 天前
Linux环境下Tomcat的安装与配置详细指南
linux·运维·tomcat