Mybatis增删改查样例
查询
id,code,keyword,readingNum,commentsNum,title,page,author,publishTime,lastUpdateTime,content,contentUrl,taskId,createTime
新增
insert into t_company_info
id,
`companyName`,
companyUnique,
legalPerson,
registCapital,
establishmentTime,
companyetAddress,
createTime
#{id,jdbcType=VARCHAR},
#{companyName,jdbcType=VARCHAR},
#{companyUnique,jdbcType=VARCHAR},
#{legalPerson,jdbcType=VARCHAR},
#{registCapital,jdbcType=VARCHAR},
#{establishmentTime,jdbcType=VARCHAR},
#{companyetAddress,jdbcType=VARCHAR},
#{createTime,jdbcType=VARCHAR}
批量insert
insert into t_bktb
(
id,
companyName,
title,
author,
publishTime,
lastUpdateTime,
content,
articleUrl,
createTime,
mark
)
values
(
#{item.id,jdbcType=VARCHAR},
#{item.companyName,jdbcType=VARCHAR},
#{item.title,jdbcType=VARCHAR},
#{item.author,jdbcType=VARCHAR},
#{item.publishTime,jdbcType=VARCHAR},
#{item.lastUpdateTime,jdbcType=VARCHAR},
#{item.content,jdbcType=VARCHAR},
#{item.articleUrl,jdbcType=VARCHAR},
#{item.createTime,jdbcType=VARCHAR},
#{item.mark,jdbcType=VARCHAR}
)
oracle语句
SELECT seq_cd_user_id.NEXTVAL FROM DUAL
INSERT INTO CD_USER
id,
username,
password,
organization,
policenumber,
auditstatus,
creattime,
isadmin,
usermobile,
idcard,
isfirst,
usertype,
provincecode,
provincename,
citycode,
cityname,
districtcode,
districtname,
VALUES
#{id},
#{userName},
#{password},
#{organization},
#{policenumber},
#{auditstatus},
#{creattime},
#{isadmin},
#{usermobile},
#{idcard},
#{isfirst},
#{usertype},
#{provincecode},
#{provincename},
#{citycode},
#{cityname},
#{districtcode},
#{districtname},
修改
UPDATE shares_eastmoney_jmzy
SET
publishTime=#{publishTime},
lastUpdateTime=#{lastUpdateTime},
content=#{content},
contentFileUrl=#{contentFileUrl}
WHERE id=#{id}
UPDATE shares_eastmoney_jmzy SET loopFlag='1' WHERE id=#{id}
批量update
update t_record_index
companyName=#{companyName},
companyUnique=#{companyUnique},
companyLoopIndex=#{companyLoopIndex},
pageLoopIndex=#{pageLoopIndex},
`type`=#{type},
`updateTime`=#{updateTime},
createTime=#{createTime}
where id=#{id}
mybatis之trim
prefix:在trim标签内sql语句加上前缀。
suffix:在trim标签内sql语句加上后缀。
suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。
prefixOverrides:指定去除多余的前缀内容
insert into cart
id,
user_id,
deal_id,
deal_sku_id,
count,
create_time,
update_time,
#{id,jdbcType=BIGINT},
#{userId,jdbcType=BIGINT},
#{dealId,jdbcType=BIGINT},
#{dealSkuId,jdbcType=BIGINT},
#{count,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP},
假设没有指定
suffixOverrides=","
执行的sql语句也许是这样的:insert into cart (id,user_id,deal_id,) values(1,2,1,);显然是错误的
指定之后语句就会变成insert into cart (id,user_id,deal_id) values(1,2,1);这样就将“,”去掉了。
前缀也是一个道理这里就不说了。