我试图获取按Springable和Thymeleaf中Pageable的喜欢次数排序的技能列表,但我遇到了麻烦。我不确定该怎么做。解决这个问题的好方法是什么?

编辑。错误:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ accountController”的bean时出错:通过字段“ skillRepository”表示的依赖关系未满足;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'skillRepository'的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalArgumentException:无法创建方法公共抽象java.util.List projekti.Skill.SkillRepository.findAllSkills(projekti.Account.Account,org.springframework.data.domain.Pageable)的查询!找不到类型为Skill的属性findAllSkills!

AccountController.java

@GetMapping("/profile/{path}")
public String profile(Model model, @PathVariable String path) {
     Account account = accountRepository.findByPath(path);
     Pageable pageable = PageRequest.of(0, 5, Sort.by("likes").descending());
     model.addAttribute("skills", skillRepository.findAllSkills(account, pageable));

     return "profile";
}


Skill.java

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Skill extends AbstractPersistable<Long> {

    @NotEmpty
    @Size(min = 1, max = 50)
    @Column
    private String name;

    @ManyToMany
    @JoinTable(
        name="who_liked",
        joinColumns=
            @JoinColumn(name="skill_id", referencedColumnName="id"),
        inverseJoinColumns=
            @JoinColumn(name="like_account_id", referencedColumnName="id"))
    private List<Account> likes = new ArrayList<>();
}


SkillRepository.java

public interface SkillRepository extends JpaRepository<Skill, Long> {
    List<Skill> findAllSkills(Account account, Pageable pageable);
}


Profile.html

<li th:each="skill : ${skills}">
      <span th:text="${skill.name}">skill</span>
      <form th:action="@{/profile/{path}/skill/{id}/like(path=${path}, id=${skill.id})}" method="POST">
            <input type="hidden" id="skillLike" name="skillLike" value="skillLike"/>
            <button type="submit"><span th:text="${#lists.size(skill.likes)}">likes</span></button>
            <span> likes</span>
     </form>
</li>

最佳答案

findAllSkills在接口JpaRepository中不存在,您可以将其更改为findAll

09-11 18:12