mybatis中使用map,进行update或insert

当update一个对象时,可以用Map

 在 xml 中 values 的值就是map的key,map的value是前端传来的,这样就不用parameterType=“********.user”  更新时就少些很多<if test=" pwd != null">去判断

原文地址:https://www.cnblogs.com/ukong/p/12244686.html

时间: 2024-07-29 17:36:01

mybatis中使用map,进行update或insert的相关文章

Mybatis中返回Map

在Mybatis中,我们通常会像下边这样用: 返回一个结果 User selectOne(User user); <select id="selectOne" parameterType="cn.lyn4ever.entity.User" resultType="cn.lyn4ever.entity.User"> select id,username,telphone from user where telphone=#{telpho

foreach属性-动态-mybatis中使用map类型参数,其中key为列名,value为列值

http://www.cnblogs.com/anruy/p/5942044.html Integer updateA(@Param("A") Map<String, Double> A); <update id="updateA" parameterType="java.util.Map"> <foreach collection="A.keys" item="key" in

Mybatis中insert中返回主键ID的方法

1.XyzMapper.xml <insertid="doSomething"parameterType="map"useGeneratedKeys="true"keyProperty="yourId"> ... </insert> 或 <insert id="doSomething" parameterType="com.xx.yy.zz.YourClass&quo

myBatis中的注解@Param、返回值为Map、JAVA读取Excel并解析文本、Class.getResource()和ClassLoader.getResource()

myBatis中的注解@Param:http://blog.csdn.net/gao36951/article/details/44258217:  http://www.cnblogs.com/thomas12112406/p/6217211.html. myBatis返回值为Map:http://blog.csdn.net/werewr342352321df/article/details/11892755. ====================== JAVA读取Excel并解析文本:h

INSERT 中ON DUPLICATE KEY UPDATE的使用

使用场景,在做全国各省ip访问统计时要将sparkStreaming的数据存在mysql中,按照一般设计,id,province,counts,time,这样就需要每次清空表,但是如果多分区的话就存在删除表的时候回出现后一个分区可能把前一个分区的数据删除掉,当然最好的办法是每次都只更新而不删除,但是如果通过代码实现比较复杂. 此时我们需要的就是如果存在则更新,如果不存在则新增. 用redis的kv就可以很容易的实现.在MySQL中也有这样的功能.INSERT 中ON DUPLICATE KEY

mybatis中one2many

上一章讲了many2one,接下来看看单向的one2many,请注意,下面的代码只做演示,不推荐在真实项目中使用.通过这个例子,也能更深刻的理解到在使用mybatiis的时候,应该更加谨慎的设计对象. 首先创建对象: public class Employee {     private Long id;     private String name; } public class Department {     private Long id;     private String nam

mybatis中的resultMap 的高级映射

引用:https://www.cnblogs.com/yansum/p/5774873.html Mybatis 高级结果映射 ResultMap Association Collection 在阅读本文章时,先说几个mybatis中容易混淆的地方: 1. mybatis中的列不是数据库里的列而是查询里的列,可以是别名(如 select user_name as userName,这时column='userName' property="userName") 2.Mysql中使用自增

mybatis中的mapper接口文件以及example类的实例函数以及详解

##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列. example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录. Criteria criteria = new Example().createCriteria(); is null;is not null; equal to(value);not equ

“mybatis 中使用foreach 传

为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismapsql <update id="updateallByEntity" parameterType="java.util.List"> update T_WEEKDAY <foreach item="item" index="