第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Springboot controller問(wèn)題

Springboot controller問(wèn)題

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


查看完整回答
反對(duì) 回復(fù) 2019-05-16
?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

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


查看完整回答
反對(duì) 回復(fù) 2019-05-16
?
呼喚遠(yuǎn)方

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊

注解用錯(cuò)了吧 你其他頁(yè)面請(qǐng)求如果是post 用postMapping get用getMapping


查看完整回答
反對(duì) 回復(fù) 2019-05-16
?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

你說(shuō)的是在首頁(yè)里面添加公共頁(yè)面吧,數(shù)據(jù)可以在主頁(yè)的controller中加載,但是公共頁(yè)面是在前端加載的,應(yīng)該用這種


查看完整回答
反對(duì) 回復(fù) 2019-05-16
  • 5 回答
  • 0 關(guān)注
  • 502 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)