尝试与JPA查询我的DB时遇到500个错误

发布于 2025-01-22 08:00:22 字数 1969 浏览 1 评论 0原文

这是我遇到的错误:

Parameter value [\] did not match expected type [java.lang.String (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [\] did not match expected type [java.lang.String (n/a)]

我有一个基本网站,它允许您创建一个包含标题,艺术家和评分的“歌曲”。您可以编辑/删除歌曲,该应用将在主页上显示所有歌曲。它具有通过降序顺序订购歌曲的功能,这些命令可起作用,而搜索功能只有一半。

我不明白怎么了,因为当我使用该功能搜索第一次搜索时,它有效,然后在第二次搜索时始终会引发此错误。

挖掘更深层次,我认为这些错误行是相关的:

    at jdk.proxy3/jdk.proxy3.$Proxy112.findByArtistContaining(Unknown Source)
    at com.cshannon.lookify.services.SongService.findByArtist(SongService.java:50)
    at com.cshannon.lookify.controllers.MainController.search(MainController.java:105)

我不明白为什么它认为我要输入的字符串是第一次使用时工作时的源头,而没有错误。我已经尝试将路线从进入帖子更改,这没有什么不同。

控制器代码:

@GetMapping("/search")
    public String search(
            Model model,
            @RequestParam(value="search") String search
            ) {
        
        if (search.isEmpty()) {
            return "redirect:/dashboard";
        }
        
        ArrayList<Song> songs = ss.findByArtist(search);
        model.addAttribute("songs", songs);
        
        return "search.jsp";
        
    }

服务:

// Find by artist
    public ArrayList<Song> findByArtist(String search) {
        
        return (ArrayList<Song>) sr.findByArtistContaining(search);
        
    }

存储库:

ArrayList<Song> findByArtistContaining(String search);

如果在这里有所帮助,那是我用来从用户那里获取字符串的表格:

<form action="/search" class="d-flex">
    <input type="search" name="search" class="form-control me-2" placeholder="Search" aria-label="Search"/>
    <input type="submit" value="Search Artists" class="btn btn-outline-success"/>
</form>

Here is the error I get:

Parameter value [\] did not match expected type [java.lang.String (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [\] did not match expected type [java.lang.String (n/a)]

I have a basic site that allows you to create a "song" that contains a title, artist and rating. You can edit/delete the songs and the app will display all the songs on the main page. It has a function to order the songs by their rating in descending order which works and a feature to search which only half works.

I don't understand what's wrong because it works when I use the feature to search the first time, then on the second search it always throws this error.

Digging a little deeper I think these error lines are relevant:

    at jdk.proxy3/jdk.proxy3.$Proxy112.findByArtistContaining(Unknown Source)
    at com.cshannon.lookify.services.SongService.findByArtist(SongService.java:50)
    at com.cshannon.lookify.controllers.MainController.search(MainController.java:105)

I can't understand why it thinks the string I am entering is an unkown source when it works the first time I do it without errors. I have tried changing the route from a Get to a Post and that doesn't make a difference.

The controller code:

@GetMapping("/search")
    public String search(
            Model model,
            @RequestParam(value="search") String search
            ) {
        
        if (search.isEmpty()) {
            return "redirect:/dashboard";
        }
        
        ArrayList<Song> songs = ss.findByArtist(search);
        model.addAttribute("songs", songs);
        
        return "search.jsp";
        
    }

The service:

// Find by artist
    public ArrayList<Song> findByArtist(String search) {
        
        return (ArrayList<Song>) sr.findByArtistContaining(search);
        
    }

The repository:

ArrayList<Song> findByArtistContaining(String search);

And if it helps here is the form I am using to get the string from the user:

<form action="/search" class="d-flex">
    <input type="search" name="search" class="form-control me-2" placeholder="Search" aria-label="Search"/>
    <input type="submit" value="Search Artists" class="btn btn-outline-success"/>
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2025-01-29 08:00:22

如果您想解决这两个安全问题 cve-2022-22968 错误,您可以使用Spring-boot版本2.5.13

If you want to fix for both security issue CVE-2022-22968 and this bug, you can use spring-boot version 2.5.13

明明#如月 2025-01-29 08:00:22

哇,我想出了这个问题。我不知道为此的低级别解释,但由于某种原因,春季启动2.6.6的错误是错误的,并将其更改为依赖项修复的2.6.3。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Wow I figured out the issue. I don't know the low level explanation for this but for some reason it's an error with Spring Boot 2.6.6 and changing it to 2.6.3 in the dependencies fixed it.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文