mybatis 参数
在MyBatis的select,insert,update,delete這些元素中都提到了parameterType這個屬性。MyBatis現(xiàn)在使用parameterType有基本類型和JAVA復(fù)雜數(shù)據(jù)類型。
基本類型:包含int,String,Date等,基本數(shù)據(jù)類型作為傳入?yún)?shù),只能傳入一個。通過#{參數(shù)名}即可獲取傳入的值
復(fù)雜類型:包含JAVA實(shí)體類,Map,通過#{屬性名}或#{Map的keyName}即可獲取傳入的值。
1.基本類型參數(shù)示例
xml文件
<select id="selectName"? ?parameterType="int"?? resultType="com.domain.Person">
??? select * from tableName where id = #{id}
</select>
Java代碼
List<Person> plist = Mapper.selectPerson(2);
for(Person persion:plist){
System.out.println(persion.toString());
}
2.JAVA 實(shí)體類型參數(shù)示例
xml文件
<select id="selectName"? ?parameterType="com.domain.Person"?? resultType="com.domain.Person">
??? select * from tableName where id = #{id}
</select>
Java代碼
Person person = new Person();
person.setId(2);
List<Person>? plist? =? Mapper.selectPerson(person)
for(Person person : plist){
System.out.println(person.toString());
}
3.Map參數(shù)示例
xml文件
<select id="selectName"? ?parameterType="Map"?? resultType="com.domain.Person">
??? select * from tableName where id = #{id} and sex=#{sex}
</select>
Java代碼
Map<String,String> map = new HasMap<String,String>();
map.put("id",2);
map.put("sex","男");
List<Person> plist? = Mapper.selectPerson(map);
for(Person person:plist){
System.out.println(person.toString());
}
總結(jié)
以上是生活随笔為你收集整理的mybatis 参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 生成excel表格并下载
- 下一篇: 手机网页屏幕自适应