gpt4 book ai didi

java - Mybatis传递多个值进行查询

转载 作者:行者123 更新时间:2023-12-01 12:25:56 27 4
gpt4 key购买 nike

我是 MyBatis 的新手。我使用 mybatis 3.1.1 版本作为 DAO 实现。
我想将 2 个参数传递给我的查询。当我尝试这样做时出现错误

Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'massPaymentDaoMapper' defined in file [D:\work\projects\paymentgw\target\PaymentGateway-1.0\WEB-INF\classes\com\company\paymentgateway\dao\MassPaymentDaoMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 45; The content of elements must consist of well-formed character data or markup.

但是如果我传递 1 个参数,我就不会收到错误。这是我的文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.company.paymentgateway.dao.MassPaymentDaoMapper">
<select id="getLastMassPaymentRecords" resultType="MassPaymentFile" parameterType="map" >
SELECT
file_id,
file_name,
record_count,
error_count,
status,
user_id
FROM mass_payment_protocol
WHERE user_id=#{user_id} AND rownum<=#{kount, javaType=Integer, jdbcType=NUMERIC}
ORDER BY created desc
</select>
</mapper>

我的java接口(interface)是

@Repository
public interface MassPaymentDaoMapper {



public List<MassPaymentFile> getLastMassPaymentRecords(Map<String,Object> params);


}

我还尝试了下一个变体

@Repository
public interface MassPaymentDaoMapper {



public List<MassPaymentFile> getLastMassPaymentRecords(@Param("user_id") int userId, @Param("kount") int count);


}

但是结果是一样的。我的错误在哪里?请帮助我

最佳答案

我发现了我的错误。

我将sql语句包含到CDATA中

 <select id="getLastMassPaymentRecords" resultType="MassPaymentFile" parameterType="map" >
<![CDATA[
SELECT
file_id,
file_name,
record_count,
error_count,
status,
user_id
FROM mass_payment_protocol
WHERE user_id=#{user_id} AND rownum<=#{count}
ORDER BY created desc
]]>
</select>

关于java - Mybatis传递多个值进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26333380/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com