Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access public static final string in mybatis sql in mapper files

I have a sql written in a MyBatis mapper file which is something like this:

<select id="somesql">
   select a,b,c from tbl_name where d = ?
</select>

The placeholder value for d is supposed to be a constant declared in a file called Constants.java as:

public static final String d = "d_value";

How do I replace the placeholder with the value without actually passing a parameter in the <select> construct? I tried #{com.pkg.name.Constants.d} but it didn't work.

No hard coding!!!

like image 604
mickeymoon Avatar asked Aug 14 '12 08:08

mickeymoon


1 Answers

<select id="getConvenienceStoreList" resultType ="Store">
    SELECT * FROM Store
    WHERE type = ${@foo.product.constant.StoreType@CONVENIENCE_STORE}
    ORDER BY id
    LIMIT #{start}, #{limit}
</select>

Reference: http://qiita.com/ApplePedlar/items/12dc389cc32f3db5557a

like image 88
Khang Dq Avatar answered Oct 07 '22 05:10

Khang Dq