MyBatis参数类型Object,且属性中含有List
来源:互联网 发布:北京一七网络 编辑:程序博客网 时间:2024/05/22 19:35
总之一句话,传递多个参数,要么用Map,要么用Bean
Mapper接口定义
int batchInsert2(@Param("st1")String st1,@Param("st2")String st2,@Param("st3")String st3, @Param("directions") List<Direction> directions);int batchInsert1(@Param("st")Station st, @Param("directions") List<Direction> directions);int batchInsert(@Param("st")Station st);
Bean定义
public class Station{ private String stationId; private List<Direction> directions;
XML实现
<insert id="batchInsert2">insert into DIRECTION(ID,STATION_ID,DIRECTION_ID,DIRECTION_NAME,DIRECTION_DESC)select CONCAT(#{st1,jdbcType=VARCHAR},DIRECTION_ID) ID, #{st2,jdbcType=VARCHAR} STATION_ID, DIRECTION_ID,CODEDESC DIRECTION_NAME,CODEDESC DIRECTION_DESC from(<foreach collection="directions" item="item" index="index" separator=" union " > select #{item.directionId,jdbcType=VARCHAR} DIRECTION_ID </foreach> )a,t_sys_code bwhere a.DIRECTION_ID = b.CODE and a.DIRECTION_ID not in(select DIRECTION_ID from DIRECTION where STATION_ID = #{st3,jdbcType=VARCHAR}) </insert>
<insert id="batchInsert1">insert into DIRECTION(ID,STATION_ID,DIRECTION_ID,DIRECTION_NAME,DIRECTION_DESC)select CONCAT(#{st.stationId,jdbcType=VARCHAR},DIRECTION_ID) ID, #{st.stationId,jdbcType=VARCHAR} STATION_ID, DIRECTION_ID,CODEDESC DIRECTION_NAME,CODEDESC DIRECTION_DESC from(<foreach collection="directions" item="item" index="index" separator=" union " > select #{item.directionId,jdbcType=VARCHAR} DIRECTION_ID </foreach> )a,t_sys_code bwhere a.DIRECTION_ID = b.CODE and a.DIRECTION_ID not in(select DIRECTION_ID from DIRECTION where STATION_ID = #{st.stationId,jdbcType=VARCHAR}) </insert>
<insert id="batchInsert">insert into DIRECTION(ID,STATION_ID,DIRECTION_ID,DIRECTION_NAME,DIRECTION_DESC)select CONCAT(#{st.stationId,jdbcType=VARCHAR},DIRECTION_ID) ID, #{st.stationId,jdbcType=VARCHAR} STATION_ID, DIRECTION_ID,CODEDESC DIRECTION_NAME,CODEDESC DIRECTION_DESC from(<foreach collection="st.directions" item="item" index="index" separator=" union " > select #{item.directionId,jdbcType=VARCHAR} DIRECTION_ID </foreach> )a,t_sys_code bwhere a.DIRECTION_ID = b.CODE and a.DIRECTION_ID not in(select DIRECTION_ID from DIRECTION where STATION_ID = #{st.stationId,jdbcType=VARCHAR}) </insert>
最初使用的方法1,batchInsert2的定义,那时候基本上是一个字符串变量,一个数组变量。这次SQL中是三次用到StationID,此时需要在参数中定义三次StationID的字符串变量
于是方法2,尝试使用Station类型的变量,在SQL中需要使用#{参数名.属性名}
进而方法2中,List变量是使用 “参数名.属性名” 的方式来引用
------------------------------------------------------------------------------------------------------
看看之间的定义,另做参考
<!-- 写入可以访问资源的所有权限 int insertMulti(@Param("menuId")int menuId, @Param("authorities")List<Integer> authorities); --> <insert id="insertMulti"> insert into auth_menu (menu_id,authority_id) values <foreach collection="authorities" item="authId" index="index" separator="," > (#{authId,jdbcType=INTEGER},#{menuId}) </foreach> </insert>
阅读全文
0 0
- MyBatis参数类型Object,且属性中含有List
- Mybatis 中遍历map 参数中的 list 和 array 属性
- MyBatis返回类型List<Object>的设置
- MyBatis-sqlMapper传入List类型参数,返回List类型参数。
- 发送请求的参数值中含有类型为textarea的input框的值且当输入有回车换行时,md5加密生成sign验证失败,
- Java List<Object>根据Object中某一个属性排序
- mybatis 返回 list<object>
- Mybatis 如何 返回 List<String> 类型 或 List<Map<String,Object>>类型
- mybatis传值List类型的参数如何遍历
- mybatis中传入String类型参数异常
- mybatis查询参数为0且类型不是string的小问题
- mybatis复合参数 map中包含list的参数
- Object类型的参数
- java 参数类型Object...
- java 参数类型Object...
- mybatis返回List<Object[]>数组
- mybatis返回List<Object[]>数据
- 按照List中Object的某个属性进行分组
- 企业级架构有多少年的历史了?
- ORACLE学习第七篇(常用处理函数)
- linux驱动中的工作队列
- android编程之得到应用程序信息
- Linux监控工具介绍系列——vmstat
- MyBatis参数类型Object,且属性中含有List
- mysql 根据分类统计每种类型数量
- JSP内置对象:使用getparametervalues()获取数据
- python-练习3
- 【Shell】 Linux下启动java程序的通用脚本sh
- flex_tree扩展_时间轴
- HTTP POST GET 本质区别详解
- Centos6.8编译安装LNMP环境(Nginx+MySQL+PHP)
- 网站seo优化笔记