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

相关推荐
stillaliveQEJ8 小时前
【MyBatis】resultType踩坑实录
mybatis
firstacui9 小时前
Keepalived+nginx+tomcat
nginx·tomcat·firefox
计算机毕设指导69 小时前
基于微信小程序民宿预订管理系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
BD_Marathon10 小时前
MyBatis处理动态设置表名
mybatis
问水っ10 小时前
Qt Creator快速入门 第三版 第17-2章 XML
xml
涵涵(互关)11 小时前
添加了 @TableId(type = IdType.AUTO) 但仍生成超大 ID
数据库·spring·mybatis
stillaliveQEJ11 小时前
【MyBatis】DML映射
java·mybatis
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ11 小时前
List、Set的相似性
windows·tomcat·list
BD_Marathon11 小时前
搭建MyBatis框架之测试添加功能(六)
mybatis
xiaoliuliu1234513 小时前
apache-tomcat-6.0.10使用步骤详解(附启动与部署教程)
java·tomcat·apache