1、单个参数

public Emp getEmp(Integer id);

取值:id==>#{id}

select * from tbl_employee where id = #{id}

2、多个参数

(1).public Emp getEmp(Integer id,String lastName);

  取值:id==>#{param1},lastName==>#{param2}

  select * from tbl_employee where id = #{param1} and last_name = #{param2}

(2).public Employee getEmpByIdAndLastName(@Param("id")Integer id,@Param("lastName")String lastName);

  取值:id==>#{id},lastName==>#{lastName}

  select * from tbl_employee where id = #{id} and last_name = #{lastName}

(3).public Emp getEmp(@Param("id")Integer id,String lastName);

  取值:id==>#{id}或者#{param1},lastName==>#{param2}

  select * from tbl_employee where id = #{id} and last_name = #{param2}

(4).public Emp getEmp(Integer id,@Param("e")String lastName);

  取值:id==>#{param1},lastName==>#{param2.lastName}或者#{e.lastName}

  select * from tbl_employee where id = #{param1} and last_name = #{e.lastName}

##特别注意:如果是Collection(List,Set)类型或者数组,是把传入的list或者数组封装在map中。

  key: Collection(collection),如果是list还可以用key(list)数组(array)

public Emp getEmpById(List<Integer> ids);

取值:取出第一个id的值,#{list[0]}

============结合源码,理解一下============

参数只有一个的时候,就拿第一个。这样#{id}取什么名无所谓。

参数为多个,就会把所有的参数放在map中{param1:"xxx",param2:"xxx"。。。。。。},可以用@param来指定map的key。

#{}可以获取map中的值或者pojo对象的属性的值;

${}可以获取map中的值或者pojo对象的属性的值;

区别:#{}是以预编译的形式,将参数设置到sql语句中;${}取出的值直接拼在sql语句中,会有安全问题。

大多数情况下,取参数用#{}。

原生sql不支持占位符的地方,使用${}取值。比如分表:select * 某个表名,排序的字段值,order by 字段值等只能用${}。

==============jdbctype======

由于全局变量中:jdbcTypeForNull = OTHER;Oracle不支持这个,所以会报错“无效列类型”jdbctype:OTHER;

解决办法两种:1.在#{email,jdbcType=NULL} 2.在全局变量中

<settings>
<setting name="jdbcTypeForNull " value="NULL"/>
</settings>