Dao向mapper傳多個引數(Mybatis)
阿新 • • 發佈:2018-12-19
第一種方案
DAO層的函式方法 :
Public User selectUser(String name,String age);
對應的Mapper.xml
<select id="selectUser" resultMap="BaseResultMap" parameterType="java.lang.String">
select * from user_user_t where user_name = #{name} and user_age = #{age}
</select>
第二種方案 : 採用Map傳多引數.
Service層呼叫
Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”對應具體的引數值”);
paramMap.put(“userAge”,”對應具體的引數值”);
User user=xxxDao.selectUser(paramMap);
}
Dao層的函式方法
Public User selectUser(Map paramMap);
對應的Mapper.xml
<select id=" selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_age=#{userAge,jdbcType=VARCHAR} </select>
第三種方案: 使用@Param註解
Dao層的函式方法
Public User selectUser(@param(“userName”)String name,@param(“userAge”)String area);
對應的Mapper.xml
<select id=" selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_age=#{userAge,jdbcType=VARCHAR} </select>