SSM项目搭建(三)前端页面 您所在的位置:网站首页 前端页面搭建 SSM项目搭建(三)前端页面

SSM项目搭建(三)前端页面

2023-08-26 10:02| 来源: 网络整理| 查看: 265

根据IP地址获取所在城市的天气情况(Java)

王杨_weikisa 回复 Trafalgar_qing: [code=java] @GetMapping("/getWeather") public String getWeather(HttpServletRequest request,Model model){ //获取真实IP地址 String ipAddress =IpUtil.getIpAddr(request); System.out.println(ipAddress); if(ipAddress.equals("0:0:0:0:0:0:0:1")) { // 1.192.119.149 鄭州 // 223.104.212.171 上海 // 42.227.160.255 南陽 ipAddress = "223.104.212.171";//如果都失败,则默认设置为上海的一个IP地址 } Weather weather = apiutil.returnWeather(ipAddress); if(weather!=null&&weather.getCity().contains("未知")) {//今日接口次数使用已达上线 model.addAttribute("weathers",weather); model.addAttribute("aqi",weather.getAqi()); model.addAttribute("city",weather.getCity()); model.addAttribute("message","今日请求次数已达上限"); }else if(weather!=null&&weather.getCity().contains("获取失败")) {//HttpGetPost请求超时(Time Out) model.addAttribute("weathers",weather); model.addAttribute("aqi",weath [/code]



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有