Escaping braces from MyBatis value - Oracle

259 Views Asked by At

This is the problematic part of my MyBatis mapper:

<foreach item="item" index="index" collection="xy" 
  open="(" separator="or" close=")">
     contains(t.mycol, '{' || #{item} || '}') > 0 
</foreach>

If, for example, the #{item} contains '}', I get:

Error code: DRG-50900
Description: text query parser error on line string, column string
Cause: bad query
  1. How do I properly escape all possibly problematic characters?
  2. where to put the logic? In the mapper/dao/service..?

So that for example '}' would become escaped (and if the text already contained escaped '}' to leave it that way).

used in the project:

  • Java 8
  • Spring
  • Oracle database
  • MyBatis
0

There are 0 best solutions below