亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Springboot controller問題

Springboot controller問題

冉冉說 2019-04-26 19:15:07
目前自己搭建了一個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";
}


查看完整回答
反對 回復 2019-05-16
?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

你要把代碼截圖出來才好分析,不然看不懂你所表達的意思。


查看完整回答
反對 回復 2019-05-16
?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

注解用錯了吧 你其他頁面請求如果是post 用postMapping get用getMapping


查看完整回答
反對 回復 2019-05-16
?
絕地無雙

TA貢獻1946條經驗 獲得超4個贊

你說的是在首頁里面添加公共頁面吧,數據可以在主頁的controller中加載,但是公共頁面是在前端加載的,應該用這種


查看完整回答
反對 回復 2019-05-16
  • 5 回答
  • 0 關注
  • 504 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號