目前自己搭建了一個(gè)OA系統(tǒng),還在搭建中,然后前端使用的是thymeleaf,我把前端的公共頁(yè)面head,foot,和左邊導(dǎo)航欄全部提取出來(lái),放在IndexController中返回,然后head的導(dǎo)航欄上有一個(gè)天氣實(shí)時(shí)展示,主頁(yè)的時(shí)候能展示,但是我打開(kāi)其他界面就不能展示,其他界面在不同的controller里面,請(qǐng)問(wèn)一下這種是什么情況,希望大神幫忙解決!下面是打開(kāi)其他頁(yè)面天氣預(yù)報(bào)無(wú)響應(yīng)代碼@Controller
@RequestMapping("/")
public class CustomerController {
@Resource
private IOaCustomerInfoService oaCustomerInfoService;
/**
* 客戶(hù)數(shù)據(jù)展示
*/
@GetMapping("/customer")
public String allCustomer(Model model) {
List<OaCustomerInfo> allList = oaCustomerInfoService.getAllCustomerInfo();
model.addAttribute("customers",allList);
return "more/customer";
}
}下面是主頁(yè)可以出現(xiàn)天氣預(yù)報(bào)的代碼@Controller
@RequestMapping("/")
public class IndexController {
@Resource
private IOaCustomerService oaCustomerService;
@Resource
private IOaCityCodeService oaCityCodeService;
@Resource
private IOaCustomerInfoService oaCustomerInfoService;
@Resource
private IOaUserPerfService oaUserPerfService;
/**
* 主頁(yè)
*/
@RequestMapping(value = "/index")
public String index() {
return "index";
}
/**
* 公共頭head頁(yè)面
*/
@RequestMapping(value = "/head")
public String test() {
return "head";
}
/**
* 公共左導(dǎo)航欄left頁(yè)面
*/
@RequestMapping(value = "/left")
public String left() {
return "left";
}
/**
* 公共尾部foot頁(yè)面
*/
@RequestMapping(value = "/foot")
public String foot() {
return "foot";
}
/**
* 賬戶(hù)設(shè)置界面
*/
@RequestMapping(value = "/settings")
public String settings() {
return "more/settings";
}
/**
* 網(wǎng)頁(yè)頭部Head天氣預(yù)報(bào)展示
*
* @param request
* @param model
*/
5 回答

至尊寶的傳說(shuō)
TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
你把你寫(xiě)的那些addressAndWeather這個(gè)方法 寫(xiě)在這兒 /**
* 公共頭head頁(yè)面
*/
@RequestMapping(value = "/head")
public String test() {
return "head";
}你的model需要和頁(yè)面一起返回
/** * 公共頭head頁(yè)面 */ @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"; }

呼喚遠(yuǎn)方
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊
注解用錯(cuò)了吧 你其他頁(yè)面請(qǐng)求如果是post 用postMapping get用getMapping

絕地?zé)o雙
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
你說(shuō)的是在首頁(yè)里面添加公共頁(yè)面吧,數(shù)據(jù)可以在主頁(yè)的controller中加載,但是公共頁(yè)面是在前端加載的,應(yīng)該用這種
添加回答
舉報(bào)
0/150
提交
取消