MyBatis return list very smart very simple answer, only need to configure Resultmap for type conversion, you DAO method directly write the return value list< corresponding object> on the line AH

Source: Internet
Author: User
Tags openid

MyBatis return list very smart very simple answer, only need to configure Resultmap for type conversion, you DAO method directly write the return value list< corresponding object> on the line AH

Dao method      Public params ) {        if(paramsnull) {            paramsnew Hashmap<string, object>();        }                 return  " Selectsimplemulti " params );    }

The corresponding MAPPER.XML configuration SQL statement

<resultmap id="Baseresultmap"Type="User"extends="Simpleresultmap"> <id property="UID"column="UID"/> <result property="Unionid"column="Unionid"/> <result property="OpenID"column="OpenID"/> <result property=" Age"column=" Age"/> <result property="Birthday"column="Birthday"/> <result property="Sex"column="Sex"/> <result property="Phone"column="Phone"/> <result property="Email"column="Email"/> <result property="QQ"column="QQ"/> <result property="WeChat"column="WeChat"/> <result property="Province"column="Province"/> <result property=" City"column=" City"/> <result property="Country"column="Country"/> <result property="Channel"column="Channel"/> <result property="Password"column="Password"/> <!--there are already simpleresultmap in the<result property="Nickname"column="Nickname"/> <result property="Headimgurl"column="Headimgurl"/> <result property="AppID"column="AppID"/> <result property="Password"column="Password"/>--<result property="backgroundimg"column="backgroundimg"/> <result property="Description"column="Description"/> <result property="Createtime"column="Create_time"/> </resultMap> <resultmap id="Simpleresultmap"Type="User"> <id property="UID"column="UID"/> <result property="Nickname"column="Nickname"/> <result property="Headimgurl"column="Headimgurl"/> </resultMap>

<select id= "Selectsimplemulti" resultmap= "Simpleresultmap" >
Select UID, nickname, Headimgurl from Tbl_user where
<trim prefixoverrides= "and" >
<if test= "Phone! = null" >
and phone = #{phone}
</if>
<if test= "Uidlist! = null and UID = = NULL" >
and UID in (
<foreach collection= "uidlist" item= "Item" separator= "," >
#{item}
</foreach>
)
</if>
<if test= "uidlist = = null and UID! = NULL" >
and uid = #{uid}
</if>
</trim>
</select>

MyBatis return list very smart very simple answer, only need to configure Resultmap for type conversion, you DAO method directly write the return value list< corresponding object> on the line AH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.