thymeleaf-scripting icon indicating copy to clipboard operation
thymeleaf-scripting copied to clipboard

Investigate a way for adding dialect like as 'mybatis:where' and 'mybatis:set' tag

Open kazuki43zoo opened this issue 7 years ago • 2 comments

In current feature, it does not support for appending and trimming SQL key-word(e.g. WHERE, AND, SET) like as <where> and <set> provided by xml based scripting language. So, we need to add the no-dynamic phrase (e.g. WHERE 1 = 1, SET id = id, etc ...) before dynamic parts. I think it is easy writing but it is troublesome rule.

I hope to be enabled to write as follow:

SELECT * FROM names
/*[# mybatis:where]*/
  WHERE
  /*[# th:if="${firstName} != null"]*/
    firstName = /*[('#{firstName}')]*/ 'Taro'
  /*[/]*/
  /*[# th:if="${lastName} != null"]*/
    AND lastName = /*[('#{lastName}')]*/ 'Yamada'
  /*[/]*/
/*[/]*/

kazuki43zoo avatar Nov 25 '18 09:11 kazuki43zoo

Hi, @kazuki43zoo .

IElementModelProcessor is valid to reproduce the function of the where tag of MyBatis. In IElementModelProcessor, it is possible to freely acquire / change the elements in the tag using IModel. However, it is important to note that evaluation of the template is performed after all processors are executed, so it can not be determined from the evaluation result SQL whether or not the where clause is required.

I thought it was an interesting attempt, so I implemented the processor sample of the where and set tags. please refer. https://github.com/yoshikawaa/mybatis-thymeleaf/blob/master/src/main/java/io/github/yoshikawaa/mybatis/MyBatisWhereModelProcesser.java https://github.com/yoshikawaa/mybatis-thymeleaf/blob/master/src/main/java/io/github/yoshikawaa/mybatis/MyBatisSetModelProcesser.java (You can clone and check the operation with JUnit.)

Regards.

yoshikawaa avatar Nov 29 '18 10:11 yoshikawaa

@yoshikawaa Thanks for your contributing. I will refer your sample.

kazuki43zoo avatar Dec 02 '18 03:12 kazuki43zoo