|
|
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + "<if test='context.name().equals(ALBUM)'>" + " album_id = #{id}"
+ "</if>" + "<if test='context.name().equals(VIDEOLIBRARY)'>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/4165294a-4ada-4bf8-ae2d-64a6ee3a24a0n%40googlegroups.com.
|
|
This is really a Java syntax question, and not related to MyBatis. To use an enum, you have to supply the enum type in the reference. You have two enum values in your example, ALBUM and VIDEOLIBRARY. Those values are defined by some enum type, maybe something like com.mybusiness.testapp.MediaTypeEnum (just a guess on my part.). To refer to a specific enum value, you would then use:
import com.mybusiness.testapp.MediaTypeEnum; ... <if test='context.name().equals(MediaTypeEnum.ALBUM)'>
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + "<if test='context.name().equals(ALBUM)'>" + " album_id = #{id}"
+ "</if>" + "<if test='context.name().equals(VIDEOLIBRARY)'>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/4165294a-4ada-4bf8-ae2d-64a6ee3a24a0n%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/em52bec978-28ba-490f-b972-495623fb199a%40asus.
|
|
Thanks to try to help me Guy.
If you read attentively what I wrote you will see that I have a problem to find the correct writing : 'ALBUM' or "ALBUM" writing doesn't right in annotation writing. I also tried `ALBUM` and it looks doesn't righting too.
I hope you understand better my need
Thanks a lot
Le lundi 21 décembre 2020 à 12:37:49 UTC+1, Guy Rouillier a écrit :
This is really a Java syntax question, and not related to MyBatis. To use an enum, you have to supply the enum type in the reference. You have two enum values in your example, ALBUM and VIDEOLIBRARY. Those values are defined by some enum type, maybe something like com.mybusiness.testapp.MediaTypeEnum (just a guess on my part.). To refer to a specific enum value, you would then use:
import com.mybusiness.testapp.MediaTypeEnum; ...
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + " album_id = #{id}"
+ "</if>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/bb727f31-c92c-4fe2-8669-18ecfbcdae32n%40googlegroups.com.
|
|
import com.mybusiness.testapp.MediaTypeEnum; would help only if you could write : + "<if test=' context.name().equals(" + MediaTypeEnum.ALBUM + ")'>", but the @Delete annotation takes a String as parameter, then you can only concatenate constant Strings. Being inside <script> tags, is just like being into the XML file, so runtime resolution.
So you can try dereferencing the enum with fully qualified name: <if test=' context.name().equals(com.mybusiness.testapp.MediaTypeEnum.ALBUM)'>: what is inside the test attribute is/must be valid java code. Maybe then, reference could be shortened to the simple name by defining type alias from fully qualified name to simple name of MediaTypeEnum. Thanks to try to help me Guy.
If you read attentively what I wrote you will see that I have a problem to find the correct writing : 'ALBUM' or "ALBUM" writing doesn't right in annotation writing. I also tried `ALBUM` and it looks doesn't righting too.
I hope you understand better my need
Thanks a lot
Le lundi 21 décembre 2020 à 12:37:49 UTC+1, Guy Rouillier a écrit :
This is really a Java syntax question, and not related to MyBatis. To use an enum, you have to supply the enum type in the reference. You have two enum values in your example, ALBUM and VIDEOLIBRARY. Those values are defined by some enum type, maybe something like com.mybusiness.testapp.MediaTypeEnum (just a guess on my part.). To refer to a specific enum value, you would then use:
import com.mybusiness.testapp.MediaTypeEnum; ...
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + " album_id = #{id}"
+ "</if>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/bb727f31-c92c-4fe2-8669-18ecfbcdae32n%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/CABepZd4%2BvEd5aMqHumxEYrUVB1%3DHnCkFvtcwrCEHgTRx6HHTNQ%40mail.gmail.com.
|
|
Guys, I'm so so sorry. I'm learning and I really understand what all of you are saying but I don't arrive to make it in practice.
So base on what you say I did this: Enum class :
public enum EContext { ALBUM, VIDEOLIBRARY, IMAGE, VIDEO, }
In the mapper:
@Delete("<script>DELETE FROM tb_some_table WHERE " + "<if test='context.name().equals(EContext.ALBUM)'>" + " album_Id = #{id}" + "</if>" + "<if test='context.name().equals(EContext.VIDEOLIBRARY)'>" + " videoLibrary_Id = #{id}" + "</if>" + "</script>") boolean deleteShared(@Param("id") int id, @Param("context") EContext context);
Now I get this error : nested exception is org.apache.ibatis.binding.BindingException: Parameter 'EContext' not found.
Thank thank so much to help me to understand
import com.mybusiness.testapp.MediaTypeEnum; would help only if you could write : + "<if test=' context.name().equals(" + MediaTypeEnum.ALBUM + ")'>", but the @Delete annotation takes a String as parameter, then you can only concatenate constant Strings. Being inside <script> tags, is just like being into the XML file, so runtime resolution.
So you can try dereferencing the enum with fully qualified name: <if test=' context.name().equals(com.mybusiness.testapp.MediaTypeEnum.ALBUM)'>: what is inside the test attribute is/must be valid java code. Maybe then, reference could be shortened to the simple name by defining type alias from fully qualified name to simple name of MediaTypeEnum.
Thanks to try to help me Guy.
If you read attentively what I wrote you will see that I have a problem to find the correct writing : 'ALBUM' or "ALBUM" writing doesn't right in annotation writing. I also tried `ALBUM` and it looks doesn't righting too.
I hope you understand better my need
Thanks a lot
Le lundi 21 décembre 2020 à 12:37:49 UTC+1, Guy Rouillier a écrit :
This is really a Java syntax question, and not related to MyBatis. To use an enum, you have to supply the enum type in the reference. You have two enum values in your example, ALBUM and VIDEOLIBRARY. Those values are defined by some enum type, maybe something like com.mybusiness.testapp.MediaTypeEnum (just a guess on my part.). To refer to a specific enum value, you would then use:
import com.mybusiness.testapp.MediaTypeEnum; ...
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + " album_id = #{id}"
+ "</if>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/dccefefa-687d-4901-9875-a0295a7fe37en%40googlegroups.com.
|
|
I got the solution from an other forum. This is the correct writing.
"<if test=\"context.name().equals('ALBUM')\">"
Guys, I'm so so sorry. I'm learning and I really understand what all of you are saying but I don't arrive to make it in practice.
So base on what you say I did this: Enum class :
public enum EContext { ALBUM, VIDEOLIBRARY, IMAGE, VIDEO, }
In the mapper:
@Delete("<script>DELETE FROM tb_some_table WHERE " + " album_Id = #{id}" + "</if>" + "<if test=' context.name().equals(EContext.VIDEOLIBRARY)'>" + " videoLibrary_Id = #{id}" boolean deleteShared(@Param("id") int id, @Param("context") EContext context);
Now I get this error : nested exception is org.apache.ibatis.binding.BindingException: Parameter 'EContext' not found.
Thank thank so much to help me to understand
import com.mybusiness.testapp.MediaTypeEnum; would help only if you could write : + "<if test=' context.name().equals(" + MediaTypeEnum.ALBUM + ")'>", but the @Delete annotation takes a String as parameter, then you can only concatenate constant Strings. Being inside <script> tags, is just like being into the XML file, so runtime resolution.
So you can try dereferencing the enum with fully qualified name: <if test=' context.name().equals(com.mybusiness.testapp.MediaTypeEnum.ALBUM)'>: what is inside the test attribute is/must be valid java code. Maybe then, reference could be shortened to the simple name by defining type alias from fully qualified name to simple name of MediaTypeEnum.
Thanks to try to help me Guy.
If you read attentively what I wrote you will see that I have a problem to find the correct writing : 'ALBUM' or "ALBUM" writing doesn't right in annotation writing. I also tried `ALBUM` and it looks doesn't righting too.
I hope you understand better my need
Thanks a lot
Le lundi 21 décembre 2020 à 12:37:49 UTC+1, Guy Rouillier a écrit :
This is really a Java syntax question, and not related to MyBatis. To use an enum, you have to supply the enum type in the reference. You have two enum values in your example, ALBUM and VIDEOLIBRARY. Those values are defined by some enum type, maybe something like com.mybusiness.testapp.MediaTypeEnum (just a guess on my part.). To refer to a specific enum value, you would then use:
import com.mybusiness.testapp.MediaTypeEnum; ...
Hello I have a problem to write the syntax using an enum in a if in MyBatis annotation.
@Delete("<script>DELETE FROM tb_a WHERE " + " album_id = #{id}"
+ "</if>" + " videolibrary_id = #{id}"
+ "</if>"
+ "</script>")
the correct syntax as fare I know is like this <if test="context.name().equals('ALBUM')"> But I don't know how to write it with annotation. I get this error message

Thanks for your help
--
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 [hidden email].
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/223f1e78-48aa-4763-a16b-20310871b35fn%40googlegroups.com.
|
|