mybatis中参数是list,parametertype怎么写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis中参数是list,parametertype怎么写相关的知识,希望对你有一定的参考价值。
参考技术A <!-- 7.2 foreach(循环List<String>参数) - 作为where中in的条件 --><select id="getStudentListByClassIds_foreach_list" resultMap="resultMap_studentEntity">
SELECT ST.STUDENT_ID,
ST.STUDENT_NAME,
ST.STUDENT_SEX,
ST.STUDENT_BIRTHDAY,
ST.STUDENT_PHOTO,
ST.CLASS_ID,
ST.PLACE_ID
FROM STUDENT_TBL ST
WHERE ST.CLASS_ID IN
<foreach collection="list" item="classIdList" open="(" separator="," close=")">
#classIdList
</foreach>
</select>本回答被提问者采纳
[mybatis]动态sql_内置参数_parameter&_databaseid
mybatis内置参数
mybatis默认还有两个内置参数:
-
_parameter;代表整个参数
-
单个参数:_parameter就是这个参数
-
多个参数:参数会被封装为一个map; _parameter就是代表这个map
-
-
_databaseId;如果配置了DatabaseIdProvider标签
- _databaseId就是代表当前数据库的别名
配置DatabaseIdProvider标签
在配置文件中配置
<databaseIdProvider type="DB_VENDOR">
<property name="MySQL" value="mysql"/>
<property name="Oracle" value="oracle"/>
</databaseIdProvider>
public List<Employee> getEmpsTestInnerParameter(Employee employee);
<!-- public List<Employee> getEmpsTestInnerParameter(Employee employee);-->
<select id="getEmpsTestInnerParameter" resultType="com.atguigu.mybatis.bean.Employee">
<!--<bind name = "_lastName" value = "'%'+lastName+'%'"/>-->
<if test = "_databaseId=='mysql'">
select * from tb1_employee
<if test = "_parameter!=null">
where last_name like #_parameter.lastName
</if>
</if>
<if test = "_databaseId == 'oracle'">
select * from employees
<if test = "_parameter!=null">
where last_name like #_parameter.lastName
</if>
</if>
</select>
@Test
public void test04() throws IOException
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession();
try
EmployeeMapperDynamicSQL mapper = sqlSession.getMapper(EmployeeMapperDynamicSQL.class);
Employee employee = new Employee();
employee.setLastName("%a%");
List<Employee> emps = mapper.getEmpsTestInnerParameter(employee);
for (Employee e : emps)
System.out.println(e);
finally
sqlSession.close();
以上是关于mybatis中参数是list,parametertype怎么写的主要内容,如果未能解决你的问题,请参考以下文章
mybatis:Parameter 'list' not found. Available parameters are [templateId, param1, param2, va
Mybatis报错:Parameter 'list' not found. Available parameters are [groupList, param1]
Mybatis使用动态SQL时报错“Parameter ‘array‘ not found. Available parameters are [collection, list]“