In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how Mybatis gets the data from the database as List type, which is very detailed and has certain reference value. Friends who are interested must read it!
Get data from the database and save it as List (save as model)
Data obtained from the database, stored in a model, need to pay attention to two points.
In dao, only the List type can be used to accept the result.
Second, write resultType clearly in mapper
/ / DAO @ Override public ArrayList getMainInfo (int id) {/ / TODO Auto-generated method stub List result = null; try {sqlSession = this.getSqlSession ();} catch (Exception e) {e.printStackTrace (); YourModel yourModel = new YourModel () Try {/ * it's strange that you can't force the type to ArrayList directly here * you can only change the type when you return below. * * / result = sqlSession.selectList (this.NAMESPACE.concat ("getMainInfo"), yourModel);} catch (Exception e) {return null;} return (ArrayList) result;} / / mapperList findByIds (Long... Ids); select from model (tableName) where ID in # {item} Mybatis stores List type data
Dao layer
Void insertList (List list)
* Mapper
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 (# {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}) these are all the contents of the article "how does Mybatis get data from the database and save it as List type" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.