首页 > 移动平台 > 详细

mybatis 的模糊查询,别名,添加后返回自增列的值,mapper中sql字段的提取 configration节点中子节点顺序

时间:2019-04-04 19:19:27      阅读:314      评论:0      收藏:0      [点我收藏+]
1.模糊查询:
<!--方式一-->
select * from user where userName like ‘%‘ #{username} ‘%‘ //防止SQL注入
<!--方式二-->
select * from user  where userName like ‘%‘||#{username}||‘%‘ //防止SQL注入的
<!--方式三-->
select * from user  where userName like ‘%‘ #{username} ‘%‘ //防止SQL注入

 Preparing: select * from user where userName like concat(‘%‘,?,‘%‘) //提交时以?提交避免了sql注入(方式1与方式2相同)
 Parameters: 李(String)

<!--方式四-->
select * from user  where userName like ‘%${value}%‘  //不能防止SQL注入,而且站位的名称必须为value

Preparing: select * from user where userName like ‘%李%‘ // 提交时与参数一起提交不能防止sql注入
 Parameters:

2.别名
<typeAliases>
<typeAlias type="entity.User" alias="user"></typeAlias>//设置单个实体类的别名 alias:别名
<package name="entity"></package>//该包下类的简单名称(只有类名,不包括包名)作为别名;
</typeAliases>
3.添加后返回自增列的值:
<insert id="add"  >
insert into `user` (loginName,password,userName)values(#{loginname},#{password},#{username})
<selectKey keyProperty="id" resultType="int">
select @@IDENTITY //用select @@identity得到上一次插入记录时自动产生的ID
</selectKey>
</insert>
4.mapper中sql字段的提取:
<sql id="clude">username,password</sql>
<select id="findall" resultType="user">
select<include refid="clude"></include> from user //refid用于定位映射sql语句重点id
</select>
5.configration节点中子节点顺序:否则报错
<!ELEMENT configuration (
properties?,
settings?,
typeAliases?,
typeHandlers?,
objectFactory?,
objectWrapperFactory?,
reflectorFactory?,
plugins?,
environments?,
databaseIdProvider?,
mappers?)
>
 

mybatis 的模糊查询,别名,添加后返回自增列的值,mapper中sql字段的提取 configration节点中子节点顺序

原文:https://www.cnblogs.com/Java60-123456/p/10656512.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!