springboot集成mybatise,mapper.xml的编写
mapper的编写:
mybatis的update的set用<set></set>包起来,便于后面做条件判断
if 之间用逗号间隔,最后一个不需要逗号
createTime由于我们首次创建的时候就已经创建进去了,所以这里就不需要update了。
SET IF用set地方可以用以标签if的判断
select 里面的id是对应的函数名和方法名,接下来写的就是关于这个id方法名的具体执行的数据库语句。
resulttype指的是:具体到哪个类去调用,要精确到类
在AreaDao里面写好了相应的方法,然后在mapper里面写相应的AreaDao.xml,这里面就写相应的方法对应的数据库语句,这就是mybatis
在java里面有dao了,那么,在resources里面也要有对应的xml文件
areaID自动生成的,其他加进去
AreaDao.xml
entity:Area
<update id="updateArea" parameterType="com.expr.applet7.entity.Area"> update tb_area <set> <if test="areaName != null">area_name=#{areaName},</if> <if test="priority != null">priority=#{priority},</if> <if test="lastEditTime != null">last_edit_time=#{lastEditTime}</if> </set> <where> area_id=#{areaId} </where> </update>
在if标签中,如果不是最后一个字段,是要加逗号的,不然会报错。。
priority只有是Integer才能在mapper的sql中判断是否为空
insert update get
Mapper.xml