我有一个独立的应用程序,该应用程序正在运行,并且在调用“ http://localhost:8080/user/person/1604438222”时出现错误。(试图从数据库获取人员ID详细信息)
2019-03-01 11:23:34.296错误52000 --- [nio-8080-exec-1] oaccC [。[。[/]。[dispatcherServlet]:Servlet [dispatcherServlet]的Servlet.service()在路径为[]的上下文中引发异常[请求处理失败;嵌套的异常是org.springframework.dao.InvalidDataAccessApiUsageException:参数值[1604438222]与预期的类型[java.lang.Integer(n / a)]不匹配;嵌套异常是java.lang.IllegalArgumentException:参数值[1604438222]与根本原因与预期类型[java.lang.Integer(n / a)]]不匹配
java.lang.IllegalArgumentException:参数值[1604438222]与预期的类型[java.lang.Integer(n / a)]不匹配 在org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54)〜[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.Final]
控制器类:
@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
+ "]";
}
}
答案 0 :(得分:2)
2,147,483,647
是Integer.MAX_VALUE
2,304,438,636
太大,无法包含在Integer
变量中
一般将Long
用作您的ID。甚至更好的是原始long
,因为理想情况下您的ID永远不应为null
答案 1 :(得分:0)
您正在POJO中使用include-before:
- \stepcounter{page}
,在存储库和控制器中使用Integer
。将它们全部更改为使用Long
或Integer
。