第一种方案
DAO层的函数方法
Public
User
selectUser(String
name
,String area);
对应的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{0} and user_area=#{1}
</select>
第二种方案
此方法采用Map传多参数.
Dao层的函数方法
Public
User
selectUser(Map paramMap);
<
select
id=
" selectUser"
resultMap=
"BaseResultMap"
>
select
*
from
user_user_t
where
user_name = #{userName
}
and
user_area=#{userArea
}
</
select
>
第三种方案
Public
User
selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);
<
select
id=
" selectUser"
resultMap=
"BaseResultMap"
>
select
*
from
user_user_t
where
user_name = #{userName,jdbcType=
VARCHAR
}
and
user_area=#{userArea,jdbcType=
VARCHAR
}
</
select
>
方案一:
优点:dao接口需要的参数比较清楚,在service层调用传参比较直观。
缺点:xml映射文件配置sql语句使用参数不是很直观,只能使用所以来获取对应的参数。
方案二:
优点:xml映射文件配置sql语句使用参数很直观。
缺点:dao接口需要的参数不是很直观,在service层调用时传参不能再编译时发现错误。
个人比较倾向于使用方案一,然后在xml文件配置sql时对传入的参数写上对应的注释,表名索引对应的参数。