2

Hello im pretty new to mybatis and is the first time im trying to use with annotations in spring boot.

My code is something like this :

@Select("<script>"
            + "SELECT t.something, s.somewhat, "
            + "FROM t.table1 t "
            + "LEFT JOIN table2 s ON t.id = s.id "
            + "WHERE s.delete_date IS NULL "
            + "<if test=\"isnew\"> "
            + "AND t.insert_date = t.update_date "
            + "AND (t.score >= s.min_score AND t.score <= s.max_score) "
            + "</if>"
            + "union "
            + "ANOTHER SIMILAR QUERY WITH ANOTHER <IF> + "</script>")
List<Map<String, Object>> methodName(@Param("isnew") Boolean isNew);

This is the error.

Caused by: java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 822;

Im almost sure there is an error of syntax very predictable but I cant find it. Here are some examples of what I tried, none of them works:

  • "<if test="isnew = true">"
  • "<if test="isnew == true">"
  • "<if test="isnew != false">"
  • "<if test="isnew"> "
  • "<if test=#{isnew}"> "
  • "<if #{isnew} = true> "

Thanks in advance

1 Answer 1

1

For those who may have the same problem this is the solution:

You have to escape the character < , because mybatis takes it as an unopened tag, &lt will work :

            + "SELECT t.something, s.somewhat, "
            + "FROM t.table1 t "
            + "LEFT JOIN table2 s ON t.id = s.id "
            + "WHERE s.delete_date IS NULL "
            + "<if test=\"isnew\"> "
            + "AND t.insert_date = t.update_date "
            + "AND (t.score >= s.min_score AND t.score lt;= s.max_score) "
            + "</if>"
            + "union "
            + "ANOTHER SIMILAR QUERY WITH ANOTHER <IF> + "</script>")
List<Map<String, Object>> methodName(@Param("isnew") Boolean isNew);```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.