您好,登錄后才能下訂單哦!
這篇文章主要介紹“mybatis怎么利用resultMap復(fù)雜類型list映射”,在日常操作中,相信很多人在mybatis怎么利用resultMap復(fù)雜類型list映射問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”mybatis怎么利用resultMap復(fù)雜類型list映射”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
<resultMap id="internetDataDTO" type="com.mdm.skr.mdm_common.dto.StrategyInternetDataDTO"> <id property="id" column="id" jdbcType="INTEGER"/> <result property="internetData" column="internet_data" jdbcType="INTEGER"/> <collection property="userList" ofType="com.mdm.skr.mdm_common.entity.SysUser"> <id property="id" column="id" jdbcType="INTEGER"/> <result property="number" column="number" jdbcType="VARCHAR"/> <result property="pushToken" column="push_token" jdbcType="VARCHAR"/> <result property="wsChannelId" column="ws_channel_id" jdbcType="VARCHAR"/> </collection> </resultMap> <select id="selectInternetDataDTOByInternetDataIdList" resultMap="internetDataDTO"> SELECT sidu.id, sidu.internet_data, su.id, su.number, su.push_token, su.ws_channel_id FROM strategy_internet_data_user sidu JOIN skr_user su on su.id = sidu.user_id WHERE sidu.id IN <foreach collection="internetDataIdList" open="(" close=")" separator="," item="internetDataId"> #{internetDataId} </foreach> </select>
@Data public class StrategyInternetDataDTO { private Integer id ; private Integer internetData ; private List<SysUser> userList ; }
@Data public class SysUser { private Integer id; private String number; private String pushToken; private String wsChannelId ; }
List<StrategyInternetDataDTO> selectInternetDataDTOByInternetDataIdList(@Param("internetDataIdList") List<Integer> internetDataIdList);
<resultMap id="internetDataDTO" type="com.mdm.skr.mdm_common.dto.StrategyInternetDataDTO"> <id property="id" column="id" jdbcType="INTEGER"/> <result property="internetData" column="internet_data" jdbcType="INTEGER"/> <collection property="userIdList" ofType="java.lang.Integer" javaType="java.util.List"> <result column="userId"/> </collection> </resultMap> <select id="selectInternetDataDTOByInternetDataIdList" resultMap="internetDataDTO"> SELECT sidu.id, sidu.internet_data, sidu.user_id userId FROM strategy_internet_data_user sidu WHERE sidu.id IN <foreach collection="internetDataIdList" open="(" close=")" separator="," item="internetDataId"> #{internetDataId} </foreach> </select>
@Data public class StrategyInternetDataDTO { private Integer id ; private Integer internetData ; private List<Integer> userIdList ; }
List<StrategyInternetDataDTO> selectInternetDataDTOByInternetDataIdList(@Param("internetDataIdList") List<Integer> internetDataIdList);
User selectUserInfo(Integer userId); <select id = "selectUserInfo" parameterType = "java.lang.Inte" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userId = #{userId , jdbcType=INTEGER} </select>
User selectUserInfo(Integer userId, String userName, String userPass); <select id = "selectUserInfo" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userId = #{arg0} and userName = #{arg1} and userPass = #{arg2} </select>
User selectUserInfo(@Param("userName")String userName, @Param("userPass")String userPass); <select id = "selectUserInfo" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userName = #{userName} and userPass = #{userPass} </select>
Map<String,Object> map = new HashMap(); map.put("userName","張三"); map.put("userPass","123"); User user = userMapper.selectUserInfo(map); User selectUserInfo(Map<String,Object> map); <select id="selectUserInfo" parameterType="java.util.Map" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userName = #{userName} and userPass = #{userPass} </select>
User user = new User(); user.setUserName("張三"); user.setUserPass("123"); User user = UserMapper.selectUserInfo(user); User selectUserInfo(User record); <select id="selectUserInfo" parameterType="com.LiuXu.bean.User" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userName = #{userName} and userPass = #{userPass} </select>
List<User> list = new ArrayList<>(); list.add(user1); list.add(user2); List<User> userList = userMapper.selectUserInfo(list); List<User> selectUserInfo(List<User> record); <select id="selectUserInfo" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from user where userId in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>
到此,關(guān)于“mybatis怎么利用resultMap復(fù)雜類型list映射”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。