Quantcast

how to query all the fields in resultmap fast when using left join?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to query all the fields in resultmap fast when using left join?

姚嘉辉
for the example below:

<resultMap id="userResultMap" type="User">  
       
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />  
       
<result property="userName" column="name" javaType="string" jdbcType="VARCHAR"/>  
       
<result property="password" column="pass" javaType="string" jdbcType="VARCHAR"/>  
       
<collection property="mobiles" column="userid" ofType="Mobile">    
           
<id property="id" column="id" javaType="int" jdbcType="INTEGER"/>    
           
<result property="telnumber" column="telnumber" javaType="string" jdbcType="VARCHAR"/>    
       
</collection>    
</
resultMap>  

<select id="selectUser" parameterType="int"  resultMap="userResultMap" >  
       
select m.id m_id,
                m
.telnumber,
                u
.id u_id,
                u
.name,
                u
.pass
               
from t_mobile m,t_user u
               
where m.userid = u.id and u.id = #{id}  
</select>

how to solve with it  if the table 
t_mobile has many field(over 50), I do not want to write all the fields in t_mobile one by one.
Is there a convinient way to do that?

--
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
|  
Report Content as Inappropriate

Re: how to query all the fields in resultmap fast when using left join?

Guy Rouillier-2
On Sat, 2017-01-14 at 04:58 -0800, 姚嘉辉 wrote:
> how to solve with it  if the table t_mobile has many field(over 50),
> I do not want to write all the fields in t_mobile one by one.
> Is there a convinient way to do that?

You don't mention which DBMS you are using.  Some, like PostgreSQL,
allow you to use abbreviated notation such as the following:

select tableA.*, tableB.col1, tableB.col2, ...

However, note that this pattern is highly discouraged in production
code.  It makes your code fragile, because if additional columns are
added to tableA, your code is likely to break in unforeseen ways.

--
Guy Rouillier

--
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
|  
Report Content as Inappropriate

Re: how to query all the fields in resultmap fast when using left join?

Iwao AVE!
In reply to this post by 姚嘉辉
Hi,

You can let MyBatis Generator [1] generate base result maps and sql elements with aliased column names.
Then your example would look something like this.

<resultMap id="userResultMap" type="User" extends="user.BaseResultMap">
  <collection property="mobiles" resultMap="mobile.BaseResultMap">    
</resultMap>   

<select id="selectUser" parameterType="int"  resultMap="userResultMap" >  
  select
    <include refid="mobile.Base_Column_List" />
    ,
    <include refid="user.Base_Column_List" />
  from t_mobile m,t_user u 
  where m.userid = u.id and u.id = #{id}
</select>

BaseResultMap and Base_Column_List are generated by Generator.

Regards,
Iwao



2017-01-14 21:58 GMT+09:00 姚嘉辉 <[hidden email]>:
for the example below:

<resultMap id="userResultMap" type="User">  
       
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />  
       
<result property="userName" column="name" javaType="string" jdbcType="VARCHAR"/>  
       
<result property="password" column="pass" javaType="string" jdbcType="VARCHAR"/>  
       
<collection property="mobiles" column="userid" ofType="Mobile">    
           
<id property="id" column="id" javaType="int" jdbcType="INTEGER"/>    
           
<result property="telnumber" column="telnumber" javaType="string" jdbcType="VARCHAR"/>    
       
</collection>    
</
resultMap>  

<select id="selectUser" parameterType="int"  resultMap="userResultMap" >  
       
select m.id m_id,
                m
.telnumber,
                u
.id u_id,
                u
.name,
                u
.pass
               
from t_mobile m,t_user u
               
where m.userid = u.id and u.id = #{id}  
</select>

how to solve with it  if the table 
t_mobile has many field(over 50), I do not want to write all the fields in t_mobile one by one.
Is there a convinient way to do that?









--


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