Calling a java static method as parameter in MyBatis 3.1 SQL Query

1,424 views
Skip to first unread message

Frédéric Camblor

unread,
Sep 26, 2014, 12:07:41 PM9/26/14
to mybati...@googlegroups.com
Hi all !

I'm wondering if there would be a syntax, in MyBatis 3.1, allowing to call a static method to generate a prepared statement parameter.

I saw the new <bind> element tag in MyBatis 3.2 (which seems to be a good option for my need), but unfortunately, I cannot upgrade to 3.2 at the moment.

I tried @{foo.Bar.myMethod()} and #{@foo.Bar@myMethod()} but none worked.

Thanks in advance.

Frédéric Camblor  
Restx commiter
Jenkins community member & plugin commiter

Message has been deleted

Ikchan Sim

unread,
Sep 26, 2014, 12:24:55 PM9/26/14
to mybati...@googlegroups.com
1. Static Field declare format.
    "@" + 'Class name include package' + "@" + 'Field name'

    Example) @package.class@property

    <if test="@org.mybatis.utility.StringUtils@TRUE">
        ORDER BY SHOP_NO

    </if>

2. Static Method declare format.
    "@" + 'Class name include package' + "@" + 'Method name(inline parameter)'
    Example) @package.class@method(#{value})

    <if test="@org.mybatis.utility.StringUtils@isBlank(#{shopStatus})">
        AND SHOP_STATUS = #{shopStatus}
    </if> 

Frédéric Camblor

unread,
Sep 26, 2014, 7:59:34 PM9/26/14
to mybati...@googlegroups.com
Hi,

It seems it doesn't work when used as a value in SQL query.

For instance, it doesn't work :
`INSERT INTO foo(col1) VALUE(@foo.Bar@myMethod())`


Frédéric Camblor  
Restx commiter
Jenkins community member & plugin commiter


--
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.
For more options, visit https://groups.google.com/d/optout.

Guy Rouillier

unread,
Sep 26, 2014, 8:17:36 PM9/26/14
to mybati...@googlegroups.com
To use as a value, enclose in ${}. The following is from working code
with enums:

tp_id = ${@com.company.rest....@OUTAGE.toInt()}
)
On 9/26/2014 7:59 PM, Frédéric Camblor wrote:
> Hi,
>
> It seems it doesn't work when used as a value in SQL query.
>
> For instance, it doesn't work :
> `INSERT INTO foo(col1) VALUE(@foo.Bar@myMethod())`
>
>
> Frédéric Camblor <http://fcamblor.wordpress.com/>
> <http://www.twitter.com/fcamblor>
> BDX.io <http://bdx.io> & Bordeaux JUG <http://bordeauxjug.org/> Leader
> Restx <http://restx.io/> commiter
> Jenkins <http://jenkins-ci.org/> community member & plugin commiter
>
>
> On Fri, Sep 26, 2014 at 6:24 PM, Ikchan Sim <plusp...@gmail.com
> <mailto:plusp...@gmail.com>> wrote:
>
> *1. Static Field declare format.*
> *"@" + 'Class name include package' **+ "@" + 'Field name'*
>
> Example) /@package.class@//property/
>
> <if test="*/@org.mybatis.utility.__StringUtils@TRUE/*">
> ORDER BY SHOP_NO
>
> </if>
> *
> 2. Static Method declare format.
> ****"@" + 'Class name include package' **+ "@" + 'Method name(inline
> parameter)'
> * Example) /@package.class@method(#{value}__)/
>
> <if
> test="*/@org.mybatis.utility.__StringUtils@isBlank(#{__shopStatus})/*">
> AND SHOP_STATUS = #{shopStatus}
> </if>
>
> --
> 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
> <mailto:mybatis-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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
> <mailto:mybatis-user...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Guy Rouillier

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

Frédéric Camblor

unread,
Sep 27, 2014, 5:41:43 AM9/27/14
to mybati...@googlegroups.com
Thanks Guy it works fine !

I tried #{@foo.Bar@myMethod()} but it didn't worked.
With ${@foo.Bar@myMethod()} it's ok !

Thanks again.

Frédéric Camblor  
Restx commiter
Jenkins community member & plugin commiter


On Sat, Sep 27, 2014 at 2:17 AM, Guy Rouillier <guy.ro...@gmail.com> wrote:
To use as a value, enclose in ${}.  The following is from working code with enums:

  tp_id = ${@com.company.rest.client.MyTyp...@OUTAGE.toInt()}

    For more options, visit https://groups.google.com/d/optout.


--
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

For more options, visit https://groups.google.com/d/optout.


--
Guy Rouillier

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
--
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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages