springboot 接口传入数组参数解析到sql查询语句中执行
时间: 2023-12-02 19:02:54
浏览: 84
在Spring Boot中,可以使用@RequestParam注解将[前端](https://geek.csdn.net/educolumn/05912bd060ca90422c50807bd9f5e9fb?spm=1055.2569.3001.10083)传入的数组参数解析成Java中的数组,然后将其传递给[myb[ati](https://geek.csdn.net/educolumn/150d7073277950db5f09620704e791cf?spm=1055.2569.3001.10083)s](https://geek.csdn.net/edu/47a0da7218b411332ba4349ff5e2a4c2?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)等ORM框架或者JDBC进行SQL查询。以下是示例[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083):
```java
@RestController
@RequestMapping("/api")
public class MyController {
@[auto](https://geek.csdn.net/educolumn/0ed23d107a440608894f63cac98e73fb?spm=1055.2569.3001.10083)wired
private MyService myService;
@GetMapping("/query")
public List<MyObject> query(@RequestParam("ids") List<Integer> ids) {
return myService.queryByIds(ids);
```