public List<T> findAllByPage(Class<T> tClass, Date startTime, Date endTime, int page, int size, Map<String, String> searchMap) { Criteria where = new Criteria(); if (startTime != null && endTime != null) { where.andOperator(Criteria.where("clickTime").gte(startTime), Criteria.where("clickTime").lte(endTime)); } for (Map.Entry<String, String> entry : searchMap.entrySet()) { where.and("\"" + entry.getKey() + "\"").is(entry.getValue()); } Query query = new Query(where); query.skip((page - 1) * size).limit(size); return mongoTemplate.find(query, tClass); } } 上述代码中 where.and 后面的查询字段 是map中的key值 代码应该怎么改
时间: 2024-01-09 16:03:29 浏览: 26
可以将 `where.and("\"" + entry.getKey() + "\"").is(entry.getValue())` 改为 `where.and(entry.getKey()).is(entry.getValue()))` ,这样就可以直接使用 map 中的 key 作为查询字段了。修改后的代码如下:
```
public List<T> findAllByPage(Class<T> tClass, Date startTime, Date endTime, int page, int size, Map<String, String> searchMap) {
Criteria where = new Criteria();
if (startTime != null && endTime != null) {
where.andOperator(Criteria.where("clickTime").gte(startTime), Criteria.where("clickTime").lte(endTime));
}
for (Map.Entry<String, String> entry : searchMap.entrySet()) {
where.and(entry.getKey()).is(entry.getValue());
}
Query query = new Query(where);
query.skip((page - 1) * size).limit(size);
return mongoTemplate.find(query, tClass);
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
在一个使用ssm框架编写的Maven项目中,在jsp页面必须放在WEB-INF中的前提下,我如何使用ajax访问WEB-INF下的名为buySeat.jsp的jsp页面?我会提供一个我在Controller中写好的跳转页面方法如下:@Controller
public class OrderController {
@RequestMapping("/jump")
public String jump(String jump) {
return jump;
}
} 并帮我优化完这段ajax代码 function initSchedule(obj){
var plist = $(".plist").find("tbody");
for(var i = 0;i < obj.data.length;i++){
plist.append(
"" +
" "+ obj.data[i].schedule_startTime +"
" +
" " + obj.data[i].schedule_movie.movie_country +" " +
" " + obj.data[i].schedule_hall.hall_name + " " +
" " + obj.data[i].schedule_price + " " +
" 选座购票 " +
" "
);
}
}
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)