获取url后面的参数

方式一

final String queryString = request.getQueryString();
System.out.println(queryString);
//解码
System.out.println(URLDecoder.decode(queryString, StandardCharsets.UTF_8));

测试:

pageSize=25&pageNum=1&sort%5B%27id%27%5D=desc&sort%5B%27name%27%5D=asc&keywords=&state=-1

pageSize=25&pageNum=1&sort%5B%27id%27%5D=desc&sort%5B%27name%27%5D=asc&keywords=&state=-1
pageSize=25&pageNum=1&sort['id']=desc&sort['name']=asc&keywords=&state=-1

方式二

Map<String, String[]> params = request.getParameterMap();
for (Map.Entry<String, String[]> param : params.entrySet()) {
    String key = param.getKey();  // 参数名
    String[] value = param.getValue();  // 参数值
    System.out.println(key + " - " + Arrays.toString(value));
}

测试

pageSize=25&pageNum=1&sort%5B%27id%27%5D=desc&sort%5B%27name%27%5D=asc&keywords=&state=-1

pageSize - [25]
pageNum - [1]
sort['id'] - [desc]
sort['name'] - [asc]
keywords - []
state - [-1]

你可能感兴趣的:(SpringBoot,JavaWeb,#,SpringMVC,java,前端,开发语言)