mybatis--foreach,choose 小结
写博客个人不喜欢写那种长篇大论。富有文採与哲学的文章,搞开发的就喜欢直击重点,仅仅记录重要的信息就好了,以后查看的时候也很方便!
mybatis 中 在if语句或when中 假设推断一个字段是否和1同样。则需使用: <if test="c==1"></if> 而不是<if test="c=1"></if> 。when中的条件也一样!
在使用foreach中,迭代集合或俗数组对象的时候。假设传入的參数就是数组或集合对象则在使用时得注意:
<foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach>
假设传入集合则 collection=“list” 。数组对象 collection="array"
官方文档说明:NOTE You can pass a List instance or an Array to MyBatis as a parameter object. When you do, MyBatis will automatically wrap it in a Map, and key it by name. List instances will be keyed to the name "list" and array instances will be keyed to the name "array".
当然还能够使用map的方式传入数组或集合对象,这样就能够直接使用自己定义的字段名称!
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步