Код: Выделить всё
package com.findersgame.questtracker.controller;
import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.findersgame.questtracker.model.MapArea;
import com.findersgame.questtracker.service.MapAreaService;
@RestController
public class MapAreaController {
private MapAreaService mapAreaService;
public MapAreaController(MapAreaService mapAreaService) {
super();
this.mapAreaService = mapAreaService;
}
@PostMapping("selected_map_areas")
public List selectedMapAreas(@RequestBody List selectedMapAreas) {
return mapAreaService.selectedMapAreas(selectedMapAreas);
}
}
Код: Выделить всё
package com.findersgame.questtracker.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import com.findersgame.questtracker.model.MapArea;
import com.findersgame.questtracker.repository.MapAreaRepository;
@Service
public class MapAreaService {
private MapAreaRepository mapAreaRepository;
public MapAreaService(MapAreaRepository mapAreaRepository) {
super();
this.mapAreaRepository = mapAreaRepository;
}
public List selectedMapAreas(List selectedIds) {
return mapAreaRepository.findAllById(selectedIds);
}
}
Код: Выделить всё
package com.findersgame.questtracker.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.findersgame.questtracker.model.MapArea;
public interface MapAreaRepository extends JpaRepository {
}
Код: Выделить всё
package com.findersgame.questtracker.model;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "map_areas")
public class MapArea {
@Id
private Integer id;
@Column
private Integer mapTabId;
@Column
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getMapTabId() {
return mapTabId;
}
public void setMapTabId(Integer mapTabId) {
this.mapTabId = mapTabId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Код: Выделить всё
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Cannot invoke "java.lang.Integer.intValue()" because "this.mapTabId" is null]
Подробнее здесь: https://stackoverflow.com/questions/790 ... ng-integer
Мобильная версия