Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 获取HttpServerErrorException:使用@PathVariable时为500 null_Spring_Spring Boot_Spring Restcontroller - Fatal编程技术网

Spring 获取HttpServerErrorException:使用@PathVariable时为500 null

Spring 获取HttpServerErrorException:使用@PathVariable时为500 null,spring,spring-boot,spring-restcontroller,Spring,Spring Boot,Spring Restcontroller,我不明白。我有一个@RestController,它应该处理像/foo?latitude=15.12345这样的请求。当然应该有更多的参数,但一个参数都不行 这是控制器: @RestController public class GooglePlaceController { private final static Logger LOGGER = LogManager.getLogger(GooglePlaceController.class); @Autowired

我不明白。我有一个
@RestController
,它应该处理像
/foo?latitude=15.12345
这样的请求。当然应该有更多的参数,但一个参数都不行

这是控制器:

@RestController
public class GooglePlaceController {

    private final static Logger LOGGER = LogManager.getLogger(GooglePlaceController.class);

    @Autowired
    private GooglePlaceService googlePlaceService;

    @RequestMapping(value = "/foo", method = RequestMethod.GET)
    public List<GooglePlaceEntity> doNearbySearch(@PathVariable Float latitude) {
        LOGGER.trace("Searching for places nearby.");
        return null;
    }

}
但问题是:

在另一个控制器中,我有:

@RequestMapping(value = "/groups/{groupId}/places", method = RequestMethod.GET)
public List<PlaceEntity> getGooglePlaces(@PathVariable Long groupId) {
    return this.userGroupService.getPlaces(groupId);
}

@RequestMapping(value = "/groups/{groupId}/google-places", method = RequestMethod.POST)
public void addGooglePlace(@PathVariable Long groupId, @RequestParam String googlePlaceId) {
    this.userGroupService.addGooglePlace(groupId, googlePlaceId);
}
@RequestMapping(value=“/groups/{groupId}/places”,method=RequestMethod.GET)
公共列表getGooglePlaces(@PathVariable Long groupId){
返回此.userGroupService.getPlaces(groupId);
}
@RequestMapping(value=“/groups/{groupId}/googleplaces”,method=RequestMethod.POST)
public void addGooglePlace(@PathVariable Long groupId,@RequestParam String googlePlaceId){
this.userGroupService.addGooglePlace(groupId,googlePlaceId);
}

这些请求工作正常。

@PathVariable
用于URL中的参数,如:
/groups/{groupId}/google places

如果参数在
之后,则应使用
@RequestParam
注释

@RequestMapping(value = "/foo", method = RequestMethod.GET)
public List<GooglePlaceEntity> doNearbySearch(@RequestParam Float latitude) {
    LOGGER.trace("Searching for places nearby.");
    return null;
}
@RequestMapping(value=“/foo”,method=RequestMethod.GET)
公共列表doNearbySearch(@RequestParam Float latitude){
trace(“搜索附近的地方”);
返回null;
}

你知道:“登瓦尔德·沃尔·劳特·伯梅恩·尼赫特·梅尔·塞恩!”-谢谢你,这是最好的选择!
@RequestMapping(value = "/groups/{groupId}/places", method = RequestMethod.GET)
public List<PlaceEntity> getGooglePlaces(@PathVariable Long groupId) {
    return this.userGroupService.getPlaces(groupId);
}

@RequestMapping(value = "/groups/{groupId}/google-places", method = RequestMethod.POST)
public void addGooglePlace(@PathVariable Long groupId, @RequestParam String googlePlaceId) {
    this.userGroupService.addGooglePlace(groupId, googlePlaceId);
}
@RequestMapping(value = "/foo", method = RequestMethod.GET)
public List<GooglePlaceEntity> doNearbySearch(@RequestParam Float latitude) {
    LOGGER.trace("Searching for places nearby.");
    return null;
}