How to specify the key explicitly when using hashMap as resultType

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

How to specify the key explicitly when using hashMap as resultType

陈抒
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
   This is my first time to use hashMap as resultType in select
statement.I hava a JavaBean called User,it contains three
members:id,nameKey and imgURI.
   Because we have about ten million users in database now,I only want
to let User.id to be key instead of all members(columns).
   How to do it?
   Thanks.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNt6PyAAoJEEXGEbEtdaVCJY8IAJL7WP+iaCMnb4Ez+ckRLfs4
GwkJ4etjJXR1ea0Y+7lq6C9dzGpT1xmPJKovPLF/FK4in0rPxJj/SU7VyFNMtA2z
QXAG1My8yk5SSJ4EGk0D9lX9b5ybwblefAPVpnaJFiMC+v9vUoK7RB6a2cD6bQRu
xnFexls7tO8pEmQdq50L972Re2OHQrd4erpuTsRLDAA6rmFD7HAzhELP2BiT9kuh
2XDqbCp6txodxelSRd9spYRmyAJiR3Dn1lys7XNWCYRP8/Lo9HxkfGsF/1Vct6v9
J3GW/quK4OFYLBTWfbz9OG3u/9jgtceE9ANwsmvG6lJIynT+1m1fh4asm5HmRqw=
=ewZt
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: How to specify the key explicitly when using hashMap as resultType

陈抒
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/27/2011 01:04 PM, chenshu wrote:
> Hello,
>    This is my first time to use hashMap as resultType in select
> statement.I hava a JavaBean called User,it contains three
> members:id,nameKey and imgURI.
>    Because we have about ten million users in database now,I only want
> to let User.id to be key instead of all members(columns).
>    How to do it?
>    Thanks.
>

Maybe I should define a ResultSetTypeHandler for this.But I can't find
any more information about interceptor and ResultSetTypeHandler for MyBatis.
Who can give me some documents or examples?
Thanks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNt66xAAoJEEXGEbEtdaVC3dAH/2ezIRJU5fMoTaMEY+jlREfO
0nQQH7cQxK67PRiuJOw4JDdiLaDqxmCklLhwAmPe69VwQwppkkBbKm0Z+z5cwPhX
HtWMCnRHnHuU3LSSzfKidFl7nzdY5JcdRLj5XH6Vey3ATMaaOG4+JzhRoyccMx8f
/y1w7UtBx8JYrNDNNWh6xXOLE+27z8b7Hrz98Xr9spjnUapIQnHKTRN5Rqsm8ngW
6d3a3S0zrdW2AezL0EYXBpwTgoO6ojfXL6ETVIgyKsCNuSQ0aPo2NY4dWri74IrB
BbEod+an2g61YnoOPcmq7aXhjmqVPiWxnTFt72z3wJtrCA56jyeVDpvS7GYc4Pk=
=9YXU
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: How to specify the key explicitly when using hashMap as resultType

extremeblue99
If your resultset consists of multiple rows, then hashmap wouldn't the
right ResultType. you probably just want to use pojo or javabean as
return type. You can define List<User> or Map<Integer, User> as the
return type for your select mapper method. For the latter, you can key
User.id using @MapKey annotation.

@MapKey("id")
Map<Integer, User> getUsers(....)


Dan

On Apr 26, 10:50 pm, chenshu <[hidden email]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/27/2011 01:04 PM, chenshu wrote:
>
> > Hello,
> >    This is my first time to use hashMap as resultType in select
> > statement.I hava a JavaBean called User,it contains three
> > members:id,nameKey and imgURI.
> >    Because we have about ten million users in database now,I only want
> > to let User.id to be key instead of all members(columns).
> >    How to do it?
> >    Thanks.
>
> Maybe I should define a ResultSetTypeHandler for this.But I can't find
> any more information about interceptor and ResultSetTypeHandler for MyBatis.
> Who can give me some documents or examples?
> Thanks.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/
>
> iQEcBAEBAgAGBQJNt66xAAoJEEXGEbEtdaVC3dAH/2ezIRJU5fMoTaMEY+jlREfO
> 0nQQH7cQxK67PRiuJOw4JDdiLaDqxmCklLhwAmPe69VwQwppkkBbKm0Z+z5cwPhX
> HtWMCnRHnHuU3LSSzfKidFl7nzdY5JcdRLj5XH6Vey3ATMaaOG4+JzhRoyccMx8f
> /y1w7UtBx8JYrNDNNWh6xXOLE+27z8b7Hrz98Xr9spjnUapIQnHKTRN5Rqsm8ngW
> 6d3a3S0zrdW2AezL0EYXBpwTgoO6ojfXL6ETVIgyKsCNuSQ0aPo2NY4dWri74IrB
> BbEod+an2g61YnoOPcmq7aXhjmqVPiWxnTFt72z3wJtrCA56jyeVDpvS7GYc4Pk=
> =9YXU
> -----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: How to specify the key explicitly when using hashMap as resultType

陈抒
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thank you very much.


On 04/28/2011 01:07 PM, extremeblue99 wrote:

> If your resultset consists of multiple rows, then hashmap wouldn't the
> right ResultType. you probably just want to use pojo or javabean as
> return type. You can define List<User> or Map<Integer, User> as the
> return type for your select mapper method. For the latter, you can key
> User.id using @MapKey annotation.
>
> @MapKey("id")
> Map<Integer, User> getUsers(....)
>
>
> Dan
>
> On Apr 26, 10:50 pm, chenshu <[hidden email]> wrote:
> On 04/27/2011 01:04 PM, chenshu wrote:
>
>>>> Hello,
>>>>    This is my first time to use hashMap as resultType in select
>>>> statement.I hava a JavaBean called User,it contains three
>>>> members:id,nameKey and imgURI.
>>>>    Because we have about ten million users in database now,I only want
>>>> to let User.id to be key instead of all members(columns).
>>>>    How to do it?
>>>>    Thanks.
>
> Maybe I should define a ResultSetTypeHandler for this.But I can't find
> any more information about interceptor and ResultSetTypeHandler for MyBatis.
> Who can give me some documents or examples?
> Thanks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNuPwqAAoJEEXGEbEtdaVCZCMH/AoDhjmm5EL3Wa+UJlm/FfaA
aOuN66ml7kT42mdoZK5qdjFqHqqnPkyjNq6Fjd8e7v2CMKra24h8uIKVyvjzL2wL
whaN/SGJxMKqc+URG00D5UXU1zf0QAv394M6Pb+OTB1R2Hi6KcpZFGX8FVeuSXMc
uzGciRMe0ESXMH26OwZa06bDF1I0k3XhnAqaBM5gqe0LM5cWxDEtwmNRJD/tXPwk
+HFiSBn7QMmYQvh65s/5nr6lEldHpYua011yk68yZusklq4ht6DOw1YX5AQST5IL
HC8ZzsoFP6Q/vOdcUFTVwX2NsAhU2E1i1tJ6zd3cjFs3Cd5j/sKX0rVvapUjzQ4=
=Y0H9
-----END PGP SIGNATURE-----