MyBatis3 - Separate input and output parameter in Select Statement

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

MyBatis3 - Separate input and output parameter in Select Statement

obl0702

Hi All, I am new to MyBatis3 using Postgresql (Spring MVC). Currently I am trying to separate the input and output of parameter with different object.


For example: Java class below have following getter and setter:

TestInput -> inputAA and inputBB

TestOutput -> outputAA and outputBB


TestMapper.java

public interface TestMapper { TestOutput QueryData(TestInput a); }


TestMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.admin.TestMapper"> <resultMap id="QueryResult" type="com.admin.modal.TestOutput and com.admin.modal.TestInput"> <result property="outputAA" column="outputAA" /> <result property="outputBB" column="outputBB" /> <result property="inputAA" column="inputAA" /> <result property="inputBB" column="inputBB" /> </resultMap> <select id="QueryData" resultMap="QueryResult"> SELECT outputAA, outputBB FROM tableAA WHERE column1 = #{inputAA} AND column2 = #{inputBB} </select> </mapper>


How can I use multiple object for a single object. I plan to use association, but there is no "foreign key" or joint criteria between these 2 objects.

Appreciate if there are any advise or feedback.

--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MyBatis3 - Separate input and output parameter in Select Statement

Guy Rouillier-2
I'm not following what you are trying to do.  resultMap is only used to map the output of a SELECT, i.e. a ResultSet. So, you would not use a resultMap to describe your input object.  You simply use the input object in your select tag:

    <select id="QueryData" parameterType="com.admin.modal.TestInput" resultMap="QueryResult">

Then your resultMap just describes the output:

    <resultMap id="QueryResult" type="com.admin.modal.TestOutput">
        <result property="outputAA" column="outputAA" />
        <result property="outputBB" column="outputBB" />
    </resultMap>

--
Guy Rouillier

------ Original Message ------
From: "obl0702" <[hidden email]>
To: "mybatis-user" <[hidden email]>
Sent: 6/19/2018 10:54:13 AM
Subject: MyBatis3 - Separate input and output parameter in Select Statement

Hi All, I am new to MyBatis3 using Postgresql (Spring MVC). Currently I am trying to separate the input and output of parameter with different object.


For example: Java class below have following getter and setter:

TestInput -> inputAA and inputBB

TestOutput -> outputAA and outputBB


TestMapper.java

public interface TestMapper { TestOutput QueryData(TestInput a); }


TestMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.admin.TestMapper"> <resultMap id="QueryResult" type="com.admin.modal.TestOutput and com.admin.modal.TestInput"> <result property="outputAA" column="outputAA" /> <result property="outputBB" column="outputBB" /> <result property="inputAA" column="inputAA" /> <result property="inputBB" column="inputBB" /> </resultMap> <select id="QueryData" resultMap="QueryResult"> SELECT outputAA, outputBB FROM tableAA WHERE column1 = #{inputAA} AND column2 = #{inputBB} </select> </mapper>


How can I use multiple object for a single object. I plan to use association, but there is no "foreign key" or joint criteria between these 2 objects.

Appreciate if there are any advise or feedback.

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