我是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界面是
@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);
}
但结果是一样的。我的错误在哪里?请帮帮我
答案 0 :(得分:1)
我发现了我的错误。
我将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>