简体   繁体   English

如何在 Springboot 中使用带有 RequestParam 的查询?

[英]How can I use query with RequestParam in Springboot?

I have this query in repository:我在存储库中有这个查询:

@Query("Select e FROM Employee e WHERE " +

            "e.startDate LIKE CONCAT('%',:date,'%')"+

           "And e.salary > LIKE CONCAT('%',:salary,'%')")
    List<Employee> searchEmployees(String query);

And this is my controller:这是我的 controller:

@GetMapping(path="/search")
   public ResponseEntity<List<Employee>> searchEmployees(@RequestParam("date")String query){
        return ResponseEntity.ok(employeeService.searchEmployees(query));
   }

I can't add second RequestParam to Controller. What is the concept when trying to add two RequestParam我无法将第二个 RequestParam 添加到 Controller。尝试添加两个 RequestParam 时的概念是什么

You can add like this;你可以这样添加;

@GetMapping(path="/search")
public ResponseEntity<List<Employee>> searchEmployees(@RequestParam("date") String query, 
                                                      @RequestParam("test") String test){
    return ResponseEntity.ok(employeeService.searchEmployees(query));
}
@GetMapping(path="/search")
   public ResponseEntity<List<Employee>> searchEmployees(@RequestParam("date")String date,@RequestParam("salary")String salary){
        return ResponseEntity.ok(employeeService.searchEmployees(query));
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM