【发布时间】:2022-01-06 01:31:58
【问题描述】:
This is my getmapping controller
@GetMapping("/email")
public List<user> doesUsernameExists(@RequestParam String username) throws IOException, InterruptedException{
System.out.println("Inside doesUsernameExists");
return this.usernameExists.findByUsername(username);
}
This is my JpaRepository interface
@Repository
public interface usernameExists extends JpaRepository<user, Long>{
List<user> findByUsername(String userName);
}
此代码运行良好,但它在 json 中给出了 ID 为用户名和密码的响应。但是, 如果用户名存在于 db 表中,我想返回 true,否则返回 false 我该怎么办,请帮忙。
【问题讨论】:
-
然后返回一个布尔值而不是列表。在 Spring Data JPA 中将您的方法重写为
boolean existsByUsername(如文档中所述)。 -
考虑将解决方案添加为答案并接受它,这样您的问题就可以结束了。谢谢!
-
如何添加解决方案作为答案?你能告诉我是stackoverflow的新手吗?
-
写在下面,
Your Answer部分。
标签: mysql spring hibernate spring-data-jpa