Feature request of add exception tag in xml

8 views
Skip to first unread message

葛俊

unread,
Oct 17, 2019, 11:25:21 PM10/17/19
to mybatis-user
Hi Mybatis Contributors.

I'm thinking of add exception tag to mybatis xml fragment like following.

Snipaste_2019-10-18_11-15-45.png






















When sometime we want to throw exception from sql when some condition can't match.

I know it can be done from java code, but it may be more straightforward if we use it in sql.

we could throw an runtimeException with the message like MybatisCoditionNotMatchException.

how do you think of it.  please share your opinion. If most approve it, I can make a pull request for it.


Thanks.


Ray Sprinkle

unread,
Oct 18, 2019, 6:28:41 AM10/18/19
to mybati...@googlegroups.com
I think that argument validation belongs in the Java code.  Using default methods you could even add the test to the mapper interface.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/7a6eea2b-b9f1-4bc4-ab98-c8ac0abd7e16%40googlegroups.com.

葛俊

unread,
Oct 20, 2019, 8:59:50 PM10/20/19
to mybatis-user
Thanks rds.

Using default method can solve the problem for if test statement.

For choose when statement, using exception tag may help for less code in java like following.

Snipaste_2019-10-21_08-55-33.png




















Thanks.






On Friday, October 18, 2019 at 6:28:41 PM UTC+8, rds wrote:
I think that argument validation belongs in the Java code.  Using default methods you could even add the test to the mapper interface.

On Thu, Oct 17, 2019, 11:25 PM 葛俊 <gejun...@gmail.com> wrote:
Hi Mybatis Contributors.

I'm thinking of add exception tag to mybatis xml fragment like following.

Snipaste_2019-10-18_11-15-45.png






















When sometime we want to throw exception from sql when some condition can't match.

I know it can be done from java code, but it may be more straightforward if we use it in sql.

we could throw an runtimeException with the message like MybatisCoditionNotMatchException.

how do you think of it.  please share your opinion. If most approve it, I can make a pull request for it.


Thanks.


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.

Ray Sprinkle

unread,
Oct 20, 2019, 9:47:57 PM10/20/19
to mybati...@googlegroups.com
My bigger point is that the argument object should be responsible validating the legal parameters and throwing the exception.  That will also result in the exception being thrown when the problem occurs.

To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/2236dff3-f318-4827-9d58-34549f56caba%40googlegroups.com.

葛俊

unread,
Oct 20, 2019, 10:23:37 PM10/20/19
to mybati...@googlegroups.com
Thanks for clarifying.

Understand. Agree for your opinion.

Thanks.

Reply all
Reply to author
Forward
0 new messages