Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kazuki43zoo opened this issue Nov 25, 2018 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kazuki43zoo
Copy link
Member

kazuki43zoo commented Nov 25, 2018

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 kazuki43zoo added enhancement New feature or request help wanted Extra attention is needed labels Nov 25, 2018
@yoshikawaa
Copy link

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.

@kazuki43zoo kazuki43zoo changed the title Investigate a way for adding dialect like as 'th:where' and 'th:set' tag Investigate a way for adding dialect like as 'mybatis:where' and 'mybatis:set' tag Nov 29, 2018
@kazuki43zoo
Copy link
Member Author

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

@kazuki43zoo kazuki43zoo added this to the General Backlog milestone Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants