我有一个独立的应用程序,在调用“ http://localhost:8080/user/person/1604438222 ”时出现错误。(试图从数据库中获取人员 ID 详细信息)
2019-03-01 11:23:34.296 错误 52000 --- [nio-8080-exec-1] oaccC[.[.[/].[dispatcherServlet]:Servlet.service() 用于 servlet [dispatcherServlet] path [] 抛出异常 [请求处理失败;嵌套异常是 org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [1604438222] did not match expected type [java.lang.Integer (n/a)]; 嵌套异常是 java.lang.IllegalArgumentException:参数值 [1604438222] 与预期类型 [java.lang.Integer (n/a)]] 不匹配,根本原因
java.lang.IllegalArgumentException:参数值 [1604438222] 与 org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54) 处的预期类型 [java.lang.Integer (n/a)] 不匹配~[hibernate -core-5.3.7.Final.jar:5.3.7.Final] 在 org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:27) ~[hibernate-core-5.3.7.Final.jar: 5.3.7.决赛]
控制器类:
@RestController @RequestMapping("/user") public class UserController { @Autowired PersonRepository personRepository; @GetMapping("/person/{prsId}") public Person getPerson(@PathVariable Long prsId) { return personRepository.findByPrsId(prsId); } }
存储库:
@Repository public interface PersonRepository extends CrudRepository<Person, Long> { Person findByPrsId(Long Id); }
POJO
@Entity @Table(name = "Person") public class Person { @Column(name = "Prs_Id") @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer prsId; @Column(name = "P_Email_Internet_Addr", nullable = true, length = 255) private String email; protected Person() { } public Integer getPrsId() { return prsId; } public void setPrsId(Integer prsId) { this.prsId = prsId; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } @Override public String toString() { return "User [prsId=" + prsId + ", email=" + email + "]"; } }