目前自己搭建了一个OA系统,还在搭建中,然后前端使用的是thymeleaf,我把前端的公共页面head,foot,和左边导航栏全部提取出来,放在IndexController中返回,然后head的导航栏上有一个天气实时展示,主页的时候能展示,但是我打开其他界面就不能展示,其他界面在不同的controller里面,请问一下这种是什么情况,希望大神帮忙解决!下面是打开其他页面天气预报无响应代码@Controller
@RequestMapping("/")
public class CustomerController {
@Resource
private IOaCustomerInfoService oaCustomerInfoService;
/**
* 客户数据展示
*/
@GetMapping("/customer")
public String allCustomer(Model model) {
List<OaCustomerInfo> allList = oaCustomerInfoService.getAllCustomerInfo();
model.addAttribute("customers",allList);
return "more/customer";
}
}下面是主页可以出现天气预报的代码@Controller
@RequestMapping("/")
public class IndexController {
@Resource
private IOaCustomerService oaCustomerService;
@Resource
private IOaCityCodeService oaCityCodeService;
@Resource
private IOaCustomerInfoService oaCustomerInfoService;
@Resource
private IOaUserPerfService oaUserPerfService;
/**
* 主页
*/
@RequestMapping(value = "/index")
public String index() {
return "index";
}
/**
* 公共头head页面
*/
@RequestMapping(value = "/head")
public String test() {
return "head";
}
/**
* 公共左导航栏left页面
*/
@RequestMapping(value = "/left")
public String left() {
return "left";
}
/**
* 公共尾部foot页面
*/
@RequestMapping(value = "/foot")
public String foot() {
return "foot";
}
/**
* 账户设置界面
*/
@RequestMapping(value = "/settings")
public String settings() {
return "more/settings";
}
/**
* 网页头部Head天气预报展示
*
* @param request
* @param model
*/
5 回答

至尊宝的传说
TA贡献1789条经验 获得超10个赞
你把你写的那些addressAndWeather这个方法 写在这儿 /**
* 公共头head页面
*/
@RequestMapping(value = "/head")
public String test() {
return "head";
}你的model需要和页面一起返回
/** * 公共头head页面 */ @RequestMapping(value = "/head") public String test(HttpServletRequest request, Model model) { String ip = IPUtil.getIpAddrByRequest(request); System.out.println("登录IP:" + ip); JSONObject address = AddressAndWeatherUtils.returnAddress(ip); String cityName = address.getString("city"); System.out.println("城市:" + cityName); cityName = cityName.substring(0, cityName.length() - 1); OaCityCode code = oaCityCodeService.getCodeByName(cityName); try { String str = AddressAndWeatherUtils.returnWeatherJson(code.getCityCode().toString()); JSONObject weatherJson = JSONObject.parseObject(str); JSONObject today = weatherJson.getJSONObject("data").getJSONArray("forecast").getJSONObject(0); String high = today.getString("high"); String low = today.getString("low"); // 截掉多余字符 high = high.substring(3); low = low.substring(3); String returnWeb = cityName + " " + low + "~" + high; model.addAttribute("weather", returnWeb); return "head"; }
添加回答
举报
0/150
提交
取消