/*
* 多个参数,使用java对象作为接口中方法的参数
* */
List<Student> selectMultiObject(QueryParam param);
<!--
多个参数,使用java对象的属性值,作为参数实际值
使用对象语法:#{属性名,javaType=类型名称,jdbcType=数据类型}很少用。
javaType:指java中的属性数据类型。
jdbcType:在数据库中的数据类型。
例如:#{paramName,javaType=java.lang.string,jdbcType=VARCHAR}
我们使用的简化方式 #{属性名} javaType,jdbcType的值mybatis反射能获取。不用提供
-->
<select id="selectMultiObject" resultType="com.bjpowernode.domain.Student">
select id, name, email, age
from student
where name = #{paramName}
or age = #{paramAge};
</select>
@Test
public void testSelectMultiObject() {
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
QueryParam param = new QueryParam();
param.setParamName("张三");
param.setParamAge(28);
List<Student> students = dao.selectMultiObject(param);
for (Student student : students) {
System.out.println("学生=" + student);
}
sqlSession.close();
}
原文:https://www.cnblogs.com/dachununique/p/14523285.html