目前自己搭建了一個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
提交
取消