输入参数:parameterType
#{} ${}区别:
1. 类型为简单类型(8个基本类型+String)
#{任意值}
${value},其中的标识符只能是value
#{}自动给String类型加上' '
${}原样输出 但是适合动态排序(动态字段)
select * from user where usename = #{name}
select * from user where usename = '${value}'
动态排序:
select * from user order by ${value} desc 根据某一个字段排序,例如name,如果加上单引号传入的name就是个常量,起不到效果
#可以防止SQL注入
${}不防止
#{} ${}相同之处:
1.都可以获取对象的值(嵌套)
2. 对象类型
#{属性名}
${属性名}
mybatis调用存储过程:
xml中:
<select id=" queryCountByTypeWithProcedure" statementType="CALLABLE" parameterType="HashMap">
{CALL queryCountByTypeWithProcedure(#{stype,jdbcType=INTEGER,mode=IN}, #{scount,jdbcType=INTEGER,mode=OUT})}
</select>
statementType="CALLABLE"设置sql的执行方法为存储过程,存储过程的输入参数stype需要通过HahMap来传
在使用时,通过hashmap的put方法传入参数,通过hashmap的get获取输出参数的值