我是靠谱客的博主 威武枫叶,这篇文章主要介绍MyBatis学习笔记(四)——两种取值符号以及ParameterType为简单、对象、嵌套对象类型.#{}、${}的区别,现在分享给大家,希望可以做个参考。

输入参数:parameterType
1.类型为 简单类型(8个基本类型+String)

.#{}、${}的区别

a.

.#{任意值}

.${value} ,其中的标识符只能是value


b.#{}自动给String类型加上’’ (自动类型转换)

${} 原样输出,但是适合于 动态排序(动态字段)

select stuno,stuname,stuage from student where stuname = #{value}

select stuno,stuname,stuage from student where stuname = ‘${value}’

动态排序:
select stuno,stuname,stuage from student order by ${value} asc


c.#{}可以防止SQL注入
${}不防止


${}、#{}相同之处:
a.都可以 获取对象的值 (嵌套类型对象)

i.获取对象值:
模糊查询,方式一:
select stuno,stuname,stuage from student where stuage= #{stuAge} or stuname like #{stuName}
Student student = new Student();
student.setStuAge(24);
student.setStuName("%w%");
List students = studentMapper.queryStudentBystuageOrstuName(student);//接口的方法->SQL

模糊查询,方式二:
student.setStuName(“w”);
select stuno,stuname,stuage from student where stuage= #{stuAge} or stuname like ‘%${stuName}%’

ii.嵌套类型对象

2.对象类型

.#{属性名}

${属性名}

最后

以上就是威武枫叶最近收集整理的关于MyBatis学习笔记(四)——两种取值符号以及ParameterType为简单、对象、嵌套对象类型.#{}、${}的区别的全部内容,更多相关MyBatis学习笔记(四)——两种取值符号以及ParameterType为简单、对象、嵌套对象类型.#{}、${}内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部