Spring MVC @GetMapping @ModelAttribute percent(%) 符号给出空值
Spring MVC @GetMapping @ModelAttribute percent(%) symbol gives null value
这是我的控制器:
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/api/v1/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping()
public List<Employee> getEmployeesBySearch(@Valid @ModelAttribute SearchDto searchDto) {
return employeeService.getEmployeesBySearch(searchDto);
}
}
这是我的 SearchDto:
public class SearchDto {
private String firstName;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
.
http://localhost:8080/api/v1/employees?firstName=%%%
http://localhost:8080/api/v1/employees?firstName=a%
http://localhost:8080/api/v1/employees?firstName=%a
每当我的 GET 请求中有百分比 (%) 符号时,它总是给出空值。
你应该对其进行编码。
a% -> a%25
%%% -> %25%25%25
name%surname -> name%25surname
您的最终 url 如下所示
http://localhost:8080/api/v1/employees?firstName=a%25
这是我的控制器:
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/api/v1/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping()
public List<Employee> getEmployeesBySearch(@Valid @ModelAttribute SearchDto searchDto) {
return employeeService.getEmployeesBySearch(searchDto);
}
}
这是我的 SearchDto:
public class SearchDto {
private String firstName;
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
.
http://localhost:8080/api/v1/employees?firstName=%%%
http://localhost:8080/api/v1/employees?firstName=a%
http://localhost:8080/api/v1/employees?firstName=%a
每当我的 GET 请求中有百分比 (%) 符号时,它总是给出空值。
你应该对其进行编码。
a% -> a%25
%%% -> %25%25%25
name%surname -> name%25surname
您的最终 url 如下所示
http://localhost:8080/api/v1/employees?firstName=a%25