ali
ali

Reputation: 155

Mybatis passing multiple values to query

I'm new to to MyBatis. I'm using mybatis 3.1.1 version as DAO implementation.
I want to pass 2 parameters to my query. When I try do it I got error

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.

But if I pass 1 parameter I got no errors. Here are my files.

<?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>

And my java interface is

@Repository
public interface MassPaymentDaoMapper {



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


}

I also tried next variant

@Repository
    public interface MassPaymentDaoMapper {



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


    }

But the result is same. Where is my mistake? please help me

Upvotes: 0

Views: 2041

Answers (1)

ali
ali

Reputation: 155

I found my mistake.

I included sql statement into 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>

Upvotes: 1

Related Questions