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

相关推荐
Nuanyt1 小时前
SSM 学习记录 第二部分 Spring整合Mybatis&Junit AOP核心概念 Spring事务管理 SpringMVC 请求与响应 Rest风格
java·spring·junit·mybatis·restful
米码收割机2 小时前
【SSM】Spring MVC_MyBatis SSM商城系统(源码+论文)【独一无二】
spring·mvc·mybatis
Full Stack Developme3 小时前
Tomcat 设计原理
java·tomcat
BullSmall1 天前
Tomcat 部署 Jenkins → Docker Jenkins 完整迁移方案
docker·tomcat·jenkins
Devin~Y1 天前
互联网大厂 Java 面试实录:Spring Boot、MyBatis、Redis、Kafka、Spring Security、RAG 与 MCP 全链路问答
java·redis·kafka·mybatis·spring security·spring mvc·sprint boot
baozhengw2 天前
信创改造-SpringBootJar包改为WAR包部署Tomcat
java·tomcat
VX_bysjlw9852 天前
基于微信小程序的宠物用品商城系统-后端74346-计算机毕设原创(免费领源码+带部署教程)
java·redis·微信小程序·eclipse·mybatis·idea·微信开发者工具
hexu_blog2 天前
springboot3集成shardingsphere4.0 分表分库
java·spring boot·mybatis
乐观的Terry2 天前
9、发布系统-Webhook自动发布
java·spring boot·spring·spring cloud·mybatis
聆听。。花开雨落3 天前
mybatis的typeHandler 作用
数据库·mybatis