0

我有一个独立的应用程序,在调用“ 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.决赛]

  1. 控制器类:

    @RestController
    @RequestMapping("/user")
    public class UserController {
    
    
        @Autowired
        PersonRepository personRepository; 
    
         @GetMapping("/person/{prsId}")
         public Person getPerson(@PathVariable Long prsId) {
              return personRepository.findByPrsId(prsId);
         }
    }
    
  2. 存储库:

    @Repository
    public interface PersonRepository extends  CrudRepository<Person, Long>
    {
        Person findByPrsId(Long Id);
    
    }
    
  3. 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 
                     + "]";
            }
        }
    
4

2 回答 2

2

2,147,483,647是值Integer.MAX_VALUE

2,304,438,636太大而不能包含在Integer变量中

Long一般用于您的 ID 。或者甚至更好,long因为您的 ID 理想情况下不应该是原语null

于 2019-03-01T19:49:04.493 回答
0

您正在IntegerPOJO 以及Long存储库和控制器中使用。将它们全部更改为使用IntegerLong

于 2019-03-01T19:50:17.393 回答