0

I am trying to create a mybatis query for the below sql query with id and message_type as input parameters

SELECT id, outbound_message, outbound_message_date,'ABC' message_type 
FROM DB
WHERE id=1200;

I tried the query below but I get a binding error.

<select id="findTask" resultMap="taskRow">
    SELECT id, outbound_message, outbound_message_date,'#{process}' message_type 
    FROM DB where id=#{id};
</select>

Is there a better way to write the message_type column?

araknoid
  • 3,065
  • 5
  • 33
  • 35
user1727217
  • 1
  • 1
  • 2

1 Answers1

0

A more elegant way to define what you want is to use a custom <sql/> block like this:

<sql id="message_type_column">
 '#{process}' message_type
</sql>

Therefore, you write your query like this:

<select ...>
    SELECT id, 
           outbound_message, 
           outbound_message_date,
           <include refid="message_type_column"/>  
    FROM DB where id=#{id}
</select>
araknoid
  • 3,065
  • 5
  • 33
  • 35