Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple arguments into a SELECT without using a complex object

Tags:

ibatis

mybatis

I am trying to pass in startSequenceId, stopSequenceId, orderNumber into the SQL map, however, i don't wish to use a typed object, i.e. parameterType="com.abc.Order", can i do so?

<select id="getSequenceIdByOrderNumber" parameterType="?" resultType="int">
    select *
    from log
    where seq_id
    between #{startSequenceId} and #{stopSequenceId}
    and order_no = #{orderNumber}
    and rownum = 1
</select>
like image 915
Oh Chin Boon Avatar asked Feb 16 '12 09:02

Oh Chin Boon


2 Answers

You can use the built in parameterType 'map' eg

Map<String, Object> parms = new HashMap<String, Object>();
parms.put("name", "abc");
parms.put("phone", "123");
parms.put("email", "[email protected]");

List<Contact> list = myBatis.selectList("getContacts",parms);


<!-- in xml mapper -->
<select id="getContacts" parameterType="map" resultMap="Contact">
  SELECT * FROM CONTACT 
  WHERE CONTACT_NAME = ${name}
  AND CONTACT_PHONE = ${phone}
  AND CONTACT_MAIl = ${email}
</select>
like image 76
johnm Avatar answered Oct 31 '22 14:10

johnm


@Chin I'll post what I had typed anyway with a simple example though you found what your looking for. My example using iBatis 2.3.4

<select id="retrieveTestXXX" parameterClass="java.util.Map" resultClass="java.lang.Integer">
    SELECT
    example_table.id
    FROM example_table
    WHERE example_table.xx_id = #testId# AND example_table.xx_id = #test2Id#
</select>

Hope this helps.

like image 25
MalsR Avatar answered Oct 31 '22 13:10

MalsR