gpt4 book ai didi

java - Spring Data JPA : java. lang.NoSuchMethodException : java. util.List.()

转载 作者:行者123 更新时间:2023-11-30 02:01:46 33 4
gpt4 key购买 nike

我正在使用 Spring Data JPA 来创建服务。我正在尝试在 JPQL 查询中使用 IN 子句

实际上我正在尝试将此 LinQ 查询转换为 JPQL

LinQ 查询

from rooms in EspaceDB.Rooms
where roomIDList.Contains(rooms.nRoomID.ToString())
select rooms;

java.lang.NoSuchMethodException: userAuth.User.<init>()

这个解决方案对我来说不起作用。在我的所有模型类中,我都有默认构造函数。

JPQL 查询语法

@Query("select room from Room as room where room.nRoomId In (:nRoomIdList)")    
List<Room> recoverDeletedRoom(@Param(value = "nRoomIdList") List<Integer> nRoomIdList);

控制台

java.lang.NoSuchMethodException: java.util.List.<init>()
at java.lang.Class.getConstructor0(Unknown Source) ~[na:1.8.0_144]
at java.lang.Class.getDeclaredConstructor(Unknown Source) ~[na:1.8.0_144]
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:209) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]

at java.lang.Thread.run(Unknown Source) [na:1.8.0_144]

房间等级

@Entity
@Table(name = "room")
public class Room implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "room_seq_generator")
@SequenceGenerator(name = "room_seq_generator", sequenceName = "room_seq",allocationSize=1)
@Column(name = "nroom_id", columnDefinition="serial")
public Integer nRoomId;

@Column(name = "ncampus_id")
public Integer nCampusId;

//....
//....

public Room() {
super();
}

房间 Controller

@PutMapping("/recoverDeletedRoom")
public List<Room> recoverRoom(List<Integer> nRoomIdList, Boolean IsActive) {
return roomService.recoverDeletedRoom(nRoomIdList, IsActive);
}

最佳答案

更改您的@PutMapping代码

@PutMapping("/recoverDeletedRoom")
public List<Room> recoverRoom(@RequestBody WrapperObject wrapperObject) {
return roomService.recoverDeletedRoom(wrapperObject.getNRoomIdList(), getIsActive());
}

并获取put映射体;

public class WrapperObject {

List<Integer> nRoomIdList;
Boolean isActive;

//getters setters
}

关于java - Spring Data JPA : java. lang.NoSuchMethodException : java. util.List.<init>(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52629519/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com