先給我出有問題的控制層代碼
@RequestMapping("weatherInfo") @Controller public class WeatherInfoController { @Autowired private WeatherInfoService weatherInfoService; /** * @description 通過城市編號獲取天氣數據 * @param cityId * @return */ @ResponseBody @RequestMapping("/getWeatherDataByCityId") public WeatherReponse getWeatherDataByCityId(@PathVariable("cityId")String cityId){ WeatherReponse resp = weatherInfoService.getWeatherDataByCityId(cityId); return resp; } }
返回404錯誤 為什么請求失敗了那?
請求路徑:http://localhost:8099/weatherInfo/getWeatherDataByCityId/101010100
查看請求路徑並沒有問題,是什么原因導致的那?
@PathVariable屬性是從uri請求路徑中讀取參數它的使用要在@RequestMapping("/getWeatherDataByCityId/{cityId}")中采用{cityId}來占位接收參數
我忘記寫{cityId}所以導致出現請求無法成功