spring mvc@getmapping@modeldattribute percent(%)符号提供空值

j1dl9f46  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(322)

这是我的控制器:

@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);
    }
}

这是我的搜索目标:

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请求中有percent(%)符号时,它总是给出null值。

zdwk9cvp

zdwk9cvp1#

你应该给它编码。
https://www.urlencoder.org/

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

您的最终url如下所示

http://localhost:8080/api/v1/employees?firstName=a%25

相关问题