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

相关推荐
R***62312 小时前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
梅梅绵绵冰2 小时前
ssm整合框架
数据库·mybatis
心灵宝贝4 小时前
申威架构SW64 KY10系统安装tomcat-9.0.10-25.ky10.sw_64.rpm详细步骤
java·架构·tomcat
nbsaas-boot5 小时前
JPA vs MyBatis 在大型 SaaS 架构中的使用边界
spring·架构·mybatis
i***66505 小时前
Spring-boot3.4最新版整合swagger和Mybatis-plus
mybatis
v***Y896 小时前
linux 设置tomcat开机启动
linux·运维·tomcat
k***81727 小时前
IDEA搭建SpringBoot,MyBatis,Mysql工程项目
spring boot·intellij-idea·mybatis
好好研究7 小时前
MyBatis框架 - 注解形式
java·数据库·mysql·maven·mybatis
l***37098 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
Dreamboat-L9 小时前
MyBatis-Plus 核心注解详解:让你告别繁琐配置
mybatis