您好,登錄后才能下訂單哦!
這篇文章主要介紹Mybatis怎么從數(shù)據(jù)庫中獲取數(shù)據(jù)存為List類型,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
從數(shù)據(jù)庫中獲取的數(shù)據(jù),存到一個(gè)model中,需要注意兩點(diǎn)。
一、在dao中,只能用List類型接受結(jié)果
二、要在mapper中寫清楚resultType
//DAO @Override public ArrayList<YourModel> getMainInfo(int id) { // TODO Auto-generated method stub List<YourModel> result = null; try{ sqlSession = this.getSqlSession(); }catch (Exception e){ e.printStackTrace(); YourModel yourModel = new YourModel(); try{ /** * 很奇怪,在這里不能直接強(qiáng)轉(zhuǎn)類型為ArrayList<GradeCheck> * 只能在下面return的時(shí)候強(qiáng)轉(zhuǎn)類型..... * */ result = sqlSession.selectList(this.NAMESPACE.concat("getMainInfo"), yourModel); }catch (Exception e){ return null; } return (ArrayList<YourModel>)result; } //mapper List<model> findByIds(Long... ids); <select id="findByIds" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from model(tableName) where ID in <foreach item="item" index="index" collection="array" open="(" separaotr="," close=")"> #{item} </foreach> </select>
Dao層
void insertList(List<TZpcjsj> list);
*Mapper
<!--批量 插入記錄 --> <insert id="insertList" > INSERT INTO t_zpcjsj(nian_fen,hang_hao,belong_to_account,zhong_ming,lai_yuan,chang_du,bi_qiang,ma_zhi,ling_zhong,yi_fen,chu_miao_qi,kai_hua_qi,tu_xu_qi,szs_miao_qi,szs_hua_qi,zqd_miao_qi,zqd_hua_qi,shou_huo_zhu_shu,zytx_zhu_xing,zytx_ye_xing,zytx_ling_xing,zytx_zhu_gao,zytx_jie_ling_xing,zytx_ye_xu_xing,ku_wei_bing_zhi,huang_wei_bing_zhi,tian_jian_jue_xuan,mark)VALUES <foreach collection="list" item="item" index="index" separator=','> (#{item.nianFen},#{item.hangHao},#{item.belongToAccount},#{item.zhongMing},#{item.laiYuan},#{item.changDu},#{item.biQiang},#{item.maZhi},#{item.lingZhong},#{item.yiFen},#{item.chuMiaoQi},#{item.kaiHuaQi},#{item.tuXuQi},#{item.szsMiaoQi},#{item.szsHuaQi},#{item.zqdMiaoQi},#{item.zqdHuaQi},#{item.shouHuoZhuShu},#{item.zytxZhuXing},#{item.zytxYeXing},#{item.zytxLingXing},#{item.zytxZhuGao},#{item.zytxJieLingXing},#{item.zytxYeXuXing},#{item.kuWeiBingZhi},#{item.huangWeiBingZhi},#{item.tianJianJueXuan},#{item.mark}) </foreach> </insert>
以上是“Mybatis怎么從數(shù)據(jù)庫中獲取數(shù)據(jù)存為List類型”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。