Hi guys,
My GetRequest gives me a 500, and I don't know why.
I am trying to make a JPQL Query to select Artist name and get the names of them with the getArtistbySomething
The SQL Select statement is working in MySQL
#My Repository:
public interface ArtistRepository extends JpaRepository<Artist, Long> {
@Query("SELECT a.name, a.id, count(p.artist) FROM Artist a, Production p, Clip c WHERE p.artist = a.id AND p.clip = c.id AND c.size > 5000 and p.date > ?1 GROUP BY p.artist order by count(p.artist) desc ")
public List<Artist> getArtistBySomething(long date);
}
My Restcontroller with the getRequest:
import ch.zhaw.springboot.entities.Artist;
import ch.zhaw.springboot.repositories.ArtistRepository;
import ch.zhaw.springboot.repositories.ClipRepository;
import ch.zhaw.springboot.repositories.ProductionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin
public class ArtistRestController {
@Autowired
private ArtistRepository artistRepository;
@Autowired
private ClipRepository clipRepository;
@Autowired
private ProductionRepository productionRepository;
@GetMapping(value = "universal2/artist")
public ResponseEntity<List<Artist>> getArtist() {
List<Artist> result = this.artistRepository.findAll();
if (!result.isEmpty()) {
return new ResponseEntity<List<Artist>>(result, HttpStatus.OK);
} else {
return new ResponseEntity<List<Artist>>(HttpStatus.NOT_FOUND);
}
}
@GetMapping(value = "universal2/artist/{date}")
public ResponseEntity<List<Artist>> getArtistBySomething(@PathVariable("date") long date) {
List<Artist> result = this.artistRepository.getArtistBySomething(date);
if (!result.isEmpty()) {
return new ResponseEntity<List<Artist>>(result, HttpStatus.OK);
} else {
return new ResponseEntity<List<Artist>>(HttpStatus.NOT_FOUND);
}
}}
The getArtistBySomething Output in JSON with URL: http://localhost:8080/universal2/artist/1516233600
"timestamp": "2021-01-07T11:57:46.250+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/universal2/artist/100': {public org.springframework.http.ResponseEntity ch.zhaw.springboot.restcontroller.ArtistRestController.getArtistById(long), public org.springframework.http.ResponseEntity ch.zhaw.springboot.restcontroller.ArtistRestController.getArtistBySomething(long)}",
"path": "/universal2/artist/1516233600"
}
I would be very grateful for any advice!
Kind regards!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…