Difference between # and $ in MyBatis

Difference between # and $ in MyBatis

This is about the difference between # and $ in MyBatis 3.0.4.

${aaa}・・・Output the value of aaa as it is.

#{aaa}・・・Escapes or, in the case of strings, encloses them in single quotes.

There is a difference between the above.

<select id="selectA" parameterType="map" resultType="map">
  SELECT AA, BB
  FROM ${schema}.TB_A AS A
  WHERE A.COLUMN = #{id}
</select>

As above, it is correct to use $ for schemas, etc., since they should not be enclosed in single quotes.

Since parameterType is map, Map is passed on the Java side.

Since resultType is also a map, the return value is also a map on the Java side.

The following is an image of the Java side.

Map cond = new HashMap<String, String>();
cond.put("schema","~~");
cond.put("id", "~~");
Map ret = (Map<String, String>) session.selectOne("selectA", cond);

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL