javaEEday05-请求响应-请求-数组集合参数
This commit is contained in:
@@ -6,6 +6,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class RequestController {
|
public class RequestController {
|
||||||
|
|
||||||
@@ -40,4 +43,18 @@ public class RequestController {
|
|||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//数组参数
|
||||||
|
@RequestMapping( "/arrayParam")
|
||||||
|
public String arrayParam(String[] hobby){
|
||||||
|
System.out.println(Arrays.toString(hobby));
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
|
||||||
|
//集合参数
|
||||||
|
@RequestMapping( "/listParam")
|
||||||
|
public String listParam(@RequestParam List<String> hobby){//由于默认采用数组参数直接获取,使用list接收,会报错,需要使用@RequestParam注解
|
||||||
|
System.out.println(hobby);
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user