Spring Data JPA : java.lang.NoSuchMethodException: java.util.List.<init>()



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

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

林Q查询

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

java.lang.NoSuchMethodException: userAuth.User.((

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

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();
}

房间控制器

@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());
}

并得到放置映射体;

public class WrapperObject {
List<Integer> nRoomIdList;
Boolean isActive;
//getters setters
}

如果您的参数没有@RequestBody注释,则会出现此异常。

仅允许对接收整个请求正文的一个参数进行@RequestBody注释。

所以在你的例子中,你需要一个包装器对象。

@PutMapping("/recoverDeletedRoom")
public List<Room> recoverRoom(@RequestBody YourWrapperObject wrapper) {
...
}

相关内容

最新更新