跳到主要内容

批量查询写法

minidao的SQL怎么写批量查询的SQL语句,需要借助格式化类DaoFormat

写法:select * from employee where id in ( ${DaoFormat.getInStrs(ids)} )

说明:参数ids是list<String>,返回的类型是字符串【'zhangsan','nihao','小王'】

第一步: 升级minidao 版本到 1.6.6+

<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>minidao-pe</artifactId>
<version>1.8.5</version>
</dependency

第二步: 编写dao

/**
* 查询返回Java对象
* @param ids
* @return
*/
@Sql("select * from employee where id in ( ${DaoFormat.getInStrs(ids)} )")
List<Map<String,Object>> getEmployeeByIds(@Param("ids") String[] ids);

第三步: 调用测试

List<Map<String,Object>> ls = employeeDao.getEmployeeByIds(new String[]{"45266BB08B9B45B3B9BA8F9488495623","603D9DB409FE407183156BAA8FA779CD"});
for(Map<String,Object> p:ls){
System.out.println(p.get("name"));
System.out.println(p.get("salary"));
}