Given that my parameterType is an ArrayList, is it possible to get the first element from that list and use it in the where clause ?
<?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="db">
<select id="selectFlag" resultType="java.lang.Boolean" parameterType="java.util.ArrayList">
select TOP 1 'true' from customers where id = ???
</select>
</mapper>
If your query uses one id, why are you sending a list and then picking the first one for the query?
Change your parameterType
to an int
(or whatever type the id has), don't send a list. This is a simple approach that also conveys the information that you are only retrieving data based on a single id. Your condition then changes to something like:
where id = #{id}
If you must absolutely send an ArrayList
(for whatever reason) then MyBatis supports OGNL expressions so something like this should work:
where id = #{list[0]}
Unfortunately MyBatis lacks on the documentation side, so you can find out about things like this only by looking at the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With