1

这是我的控制器:

@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 请求中有百分比(%)符号时,它总是给出空值。

4

1 回答 1

1

您应该对其进行编码。

https://www.urlencoder.org/

a%  ->  a%25
%%% ->  %25%25%25
name%surname -> name%25surname

您的最终网址如下所示

http://localhost:8080/api/v1/employees?firstName=a%25
于 2021-01-18T11:17:14.303 回答