Mybatis How to map a column from another table to a String list? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Can I pass a List as a parameter to a MyBatis mapper?difference between collection and association mapping in mybatis 3How do I efficiently iterate over each entry in a Java Map?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How to check if a string “StartsWith” another string?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How to split a string in JavaHow do I check if a string contains a specific word?How do I convert a String to an int in Java?

Is Bran literally the world's memory?

Did war bonds have better investment alternatives during WWII?

Philosophers who were composers?

Why did Europeans not widely domesticate foxes?

Bright yellow or light yellow?

Is there a verb for listening stealthily?

What is ls Largest Number Formed by only moving two sticks in 508?

Could a cockatrice have parasitic embryos?

Where to find documentation for `whois` command options?

Stretch a Tikz tree

So I pre ordered a game on my friends home screen but on my Xbox, does that mean I don't get the game and I lost 60$?

What is a good proxy for government quality?

What helicopter has the most rotor blades?

Protagonist's race is hidden - should I reveal it?

Why aren't road bicycle wheels tiny?

How do I deal with an erroneously large refund?

Israeli soda type drink

What *exactly* is electrical current, voltage, and resistance?

Mechanism of the formation of peracetic acid

Page Layouts : 1 column , 2 columns-left , 2 columns-right , 3 column

Where can I find how to tex symbols for different fonts?

When speaking, how do you change your mind mid-sentence?

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

Will I be more secure with my own router behind my ISP's router?



Mybatis How to map a column from another table to a String list?



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Can I pass a List as a parameter to a MyBatis mapper?difference between collection and association mapping in mybatis 3How do I efficiently iterate over each entry in a Java Map?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How to check if a string “StartsWith” another string?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How to split a string in JavaHow do I check if a string contains a specific word?How do I convert a String to an int in Java?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a table t_comment, and a table t_comment_photo.



t_comment has column id, content;
t_comment_photo has column id, comment_id, photo_url.
t_comment_pohto contains the url of comment photos, a comment can have 0 to many comment photos.



These are their java classes:



public class ToyComment 
private Integer id;
private String content;
private List<String> urls;
...

public class CommentPhoto
private Integer id;
private String commentId;
private String comment_url;
...



Here is the <select> content in mapper:



<select id="getToyCommentList"
resultType="com.domain.ToyComment">
c.id, c.content,p.user_photo_url userPhoto
from t_comment c left join t_comment_photo p
on c.id = p.comment_id
</select>


When I try to map the userPhoto queried from table t_comment_photo to a element of the list inside the java class ToyComment, I am getting errors.



The resultMap I am trying to fix is:



<resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
<result column="id" jdbcType="VARCHAR" property="id" />
<result column="content" jdbcType="VARCHAR" property="content" />
<!-- <result property="urls" jdbcType="VARCHAR" javaType="java.util.ArrayList" column="userPhoto" /> -->
<collection property="urls" javaType="list" jdbcType="VARCHAR" column="userPhoto"></collection>
</resultMap>


I tried both <property> and <collection>, but neither are working.



When I used <collection>, I got "Mapped Statements collection already contains value for com.toy.mapper.ToyCommentMapper.getToyCommentListByToyId" error, when I used <result>, I got "No typehandler found for property userPhotos".
Use "java.util.ArrayList" or "list" for javaType doesn't change the output error.



I tried to search for "mybatis map to string list", but most are about mapping to a list of objects.



How to fix it right?










share|improve this question



















  • 1





    You can try this answer here. Use foreach maybe help you.

    – Reimulikeaboss
    Mar 11 at 2:03

















0















I have a table t_comment, and a table t_comment_photo.



t_comment has column id, content;
t_comment_photo has column id, comment_id, photo_url.
t_comment_pohto contains the url of comment photos, a comment can have 0 to many comment photos.



These are their java classes:



public class ToyComment 
private Integer id;
private String content;
private List<String> urls;
...

public class CommentPhoto
private Integer id;
private String commentId;
private String comment_url;
...



Here is the <select> content in mapper:



<select id="getToyCommentList"
resultType="com.domain.ToyComment">
c.id, c.content,p.user_photo_url userPhoto
from t_comment c left join t_comment_photo p
on c.id = p.comment_id
</select>


When I try to map the userPhoto queried from table t_comment_photo to a element of the list inside the java class ToyComment, I am getting errors.



The resultMap I am trying to fix is:



<resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
<result column="id" jdbcType="VARCHAR" property="id" />
<result column="content" jdbcType="VARCHAR" property="content" />
<!-- <result property="urls" jdbcType="VARCHAR" javaType="java.util.ArrayList" column="userPhoto" /> -->
<collection property="urls" javaType="list" jdbcType="VARCHAR" column="userPhoto"></collection>
</resultMap>


I tried both <property> and <collection>, but neither are working.



When I used <collection>, I got "Mapped Statements collection already contains value for com.toy.mapper.ToyCommentMapper.getToyCommentListByToyId" error, when I used <result>, I got "No typehandler found for property userPhotos".
Use "java.util.ArrayList" or "list" for javaType doesn't change the output error.



I tried to search for "mybatis map to string list", but most are about mapping to a list of objects.



How to fix it right?










share|improve this question



















  • 1





    You can try this answer here. Use foreach maybe help you.

    – Reimulikeaboss
    Mar 11 at 2:03













0












0








0








I have a table t_comment, and a table t_comment_photo.



t_comment has column id, content;
t_comment_photo has column id, comment_id, photo_url.
t_comment_pohto contains the url of comment photos, a comment can have 0 to many comment photos.



These are their java classes:



public class ToyComment 
private Integer id;
private String content;
private List<String> urls;
...

public class CommentPhoto
private Integer id;
private String commentId;
private String comment_url;
...



Here is the <select> content in mapper:



<select id="getToyCommentList"
resultType="com.domain.ToyComment">
c.id, c.content,p.user_photo_url userPhoto
from t_comment c left join t_comment_photo p
on c.id = p.comment_id
</select>


When I try to map the userPhoto queried from table t_comment_photo to a element of the list inside the java class ToyComment, I am getting errors.



The resultMap I am trying to fix is:



<resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
<result column="id" jdbcType="VARCHAR" property="id" />
<result column="content" jdbcType="VARCHAR" property="content" />
<!-- <result property="urls" jdbcType="VARCHAR" javaType="java.util.ArrayList" column="userPhoto" /> -->
<collection property="urls" javaType="list" jdbcType="VARCHAR" column="userPhoto"></collection>
</resultMap>


I tried both <property> and <collection>, but neither are working.



When I used <collection>, I got "Mapped Statements collection already contains value for com.toy.mapper.ToyCommentMapper.getToyCommentListByToyId" error, when I used <result>, I got "No typehandler found for property userPhotos".
Use "java.util.ArrayList" or "list" for javaType doesn't change the output error.



I tried to search for "mybatis map to string list", but most are about mapping to a list of objects.



How to fix it right?










share|improve this question
















I have a table t_comment, and a table t_comment_photo.



t_comment has column id, content;
t_comment_photo has column id, comment_id, photo_url.
t_comment_pohto contains the url of comment photos, a comment can have 0 to many comment photos.



These are their java classes:



public class ToyComment 
private Integer id;
private String content;
private List<String> urls;
...

public class CommentPhoto
private Integer id;
private String commentId;
private String comment_url;
...



Here is the <select> content in mapper:



<select id="getToyCommentList"
resultType="com.domain.ToyComment">
c.id, c.content,p.user_photo_url userPhoto
from t_comment c left join t_comment_photo p
on c.id = p.comment_id
</select>


When I try to map the userPhoto queried from table t_comment_photo to a element of the list inside the java class ToyComment, I am getting errors.



The resultMap I am trying to fix is:



<resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
<result column="id" jdbcType="VARCHAR" property="id" />
<result column="content" jdbcType="VARCHAR" property="content" />
<!-- <result property="urls" jdbcType="VARCHAR" javaType="java.util.ArrayList" column="userPhoto" /> -->
<collection property="urls" javaType="list" jdbcType="VARCHAR" column="userPhoto"></collection>
</resultMap>


I tried both <property> and <collection>, but neither are working.



When I used <collection>, I got "Mapped Statements collection already contains value for com.toy.mapper.ToyCommentMapper.getToyCommentListByToyId" error, when I used <result>, I got "No typehandler found for property userPhotos".
Use "java.util.ArrayList" or "list" for javaType doesn't change the output error.



I tried to search for "mybatis map to string list", but most are about mapping to a list of objects.



How to fix it right?







java string collections mapping mybatis






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 12:08









Mr Lister

35.7k1078121




35.7k1078121










asked Mar 9 at 5:04









fallfall

349521




349521







  • 1





    You can try this answer here. Use foreach maybe help you.

    – Reimulikeaboss
    Mar 11 at 2:03












  • 1





    You can try this answer here. Use foreach maybe help you.

    – Reimulikeaboss
    Mar 11 at 2:03







1




1





You can try this answer here. Use foreach maybe help you.

– Reimulikeaboss
Mar 11 at 2:03





You can try this answer here. Use foreach maybe help you.

– Reimulikeaboss
Mar 11 at 2:03












1 Answer
1






active

oldest

votes


















1














The result map should look as follows:



<resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
<id column="id" property="id" />
<result column="content" property="content" />
<collection property="urls" javaType="list"
ofType="string">
<result column="userPhoto" />
</collection>
</resultMap>


A few notes:



  • Specify <id /> when using <collection />. It improves efficiency and is required in some cases.

  • In <select />, you need to specify resultMap instead of resultType (obviously).

  • This is a tricky case and we have added an FAQ entry just recently.





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074171%2fmybatis-how-to-map-a-column-from-another-table-to-a-string-list%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The result map should look as follows:



    <resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
    <id column="id" property="id" />
    <result column="content" property="content" />
    <collection property="urls" javaType="list"
    ofType="string">
    <result column="userPhoto" />
    </collection>
    </resultMap>


    A few notes:



    • Specify <id /> when using <collection />. It improves efficiency and is required in some cases.

    • In <select />, you need to specify resultMap instead of resultType (obviously).

    • This is a tricky case and we have added an FAQ entry just recently.





    share|improve this answer



























      1














      The result map should look as follows:



      <resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
      <id column="id" property="id" />
      <result column="content" property="content" />
      <collection property="urls" javaType="list"
      ofType="string">
      <result column="userPhoto" />
      </collection>
      </resultMap>


      A few notes:



      • Specify <id /> when using <collection />. It improves efficiency and is required in some cases.

      • In <select />, you need to specify resultMap instead of resultType (obviously).

      • This is a tricky case and we have added an FAQ entry just recently.





      share|improve this answer

























        1












        1








        1







        The result map should look as follows:



        <resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
        <id column="id" property="id" />
        <result column="content" property="content" />
        <collection property="urls" javaType="list"
        ofType="string">
        <result column="userPhoto" />
        </collection>
        </resultMap>


        A few notes:



        • Specify <id /> when using <collection />. It improves efficiency and is required in some cases.

        • In <select />, you need to specify resultMap instead of resultType (obviously).

        • This is a tricky case and we have added an FAQ entry just recently.





        share|improve this answer













        The result map should look as follows:



        <resultMap id="ToyCommentResultMap" type="com.domain.ToyComment">
        <id column="id" property="id" />
        <result column="content" property="content" />
        <collection property="urls" javaType="list"
        ofType="string">
        <result column="userPhoto" />
        </collection>
        </resultMap>


        A few notes:



        • Specify <id /> when using <collection />. It improves efficiency and is required in some cases.

        • In <select />, you need to specify resultMap instead of resultType (obviously).

        • This is a tricky case and we have added an FAQ entry just recently.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 4 at 13:57









        aveave

        8613




        8613





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074171%2fmybatis-how-to-map-a-column-from-another-table-to-a-string-list%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved