AngularJs,如何在URL中设置空字符串

时间:2015-10-24 13:04:56

标签: angularjs

在控制器中我有以下功能:

    @RequestMapping(value = "administrator/listAuthor/{authorName}/{pageNo}", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json")
    public List<Author> listAuthors(@PathVariable(value = "authorName") String authorName,
            @PathVariable(value = "pageNo") Integer pageNo) {
        try {
            if (authorName == null) {
                authorName = "";
            }
            if (pageNo == null) {
                pageNo = 1;
            }
            return adminService.listAuthor(authorName, pageNo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

此函数根据“authorName”和“pageNo”从mysql数据库中获取并返回数据。例如,当“authorName = a”和“pageNo = 1”时,我有:

Data I get when "authorName = a" and "pageNo = 1"

现在我想将“authorName”设置为“”(空字符串),这样我就可以从mysql数据库中获取所有数据(因为后端的SQL语句“%+”“+%”将返回所有数据)。

如果我想设置authorName =空字符串,该怎么办?

http://localhost:8080/spring/administrator/listAuthor/ {empty string} / 1

提前致谢!

1 个答案:

答案 0 :(得分:0)

我不认为你可以将空sting编码为url,我建议你做的是声明一些常量,这将是你的代码以清空字符串 - 例如null。

示例:

administrator/listAuthor/null/90

然后,在服务器端,检查authorName是否为null,并相应地将local参数设置为空参数。