關於客戶端向服務端發送請求顯示404問題


先給我出有問題的控制層代碼

@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}所以導致出現請求無法成功

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM