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

相关推荐
步行cgn1 天前
MyBatis 实现分页查询
mybatis
山甫aa1 天前
Javaweb---MyBatis增删改查
java·数据库·后端·mybatis·springboot
竹枝溪1 天前
Tomcat与Servlet全套小白教程
java·servlet·tomcat·cookie·filter·session·listener
choumou_M1 天前
SpringBoot_2:MyBatis-Generator插件使用教程
spring boot·tomcat·mybatis
SQL-First布道者1 天前
全面解构传统持久层框架,拥抱真正的 SQL-First
java·数据库·spring boot·sql·spring·mybatis·spring jdbc
ly76891 天前
XML 从入门到实践:语法、命名空间、XPath、XSD 与 Java 安全解析
xml·java·python
晚安code3 天前
MyBatis-Plus 分页插件与字段自动填充:两行配置告别 CRUD 重复劳动
mybatis
SQL-First布道者4 天前
持久层框架的评价标准:只有一个
java·spring boot·spring·tomcat·mybatis·spring jdbc
步行cgn4 天前
MyBatis 高级映射与延迟加载完全指南
java·tomcat·mybatis