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

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

spring 能不能在方法內(nèi)決定返回類型

spring 能不能在方法內(nèi)決定返回類型

縹緲止盈 2019-03-30 11:31:41
這個(gè)是直接對(duì)應(yīng)index模型java@RequestMapping(value="/")publicStringindex(Mapmap){map.put("title","");map.put("keywords","");map.put("description","");return"index";}這個(gè)是直接返回index字符串java@RequestMapping(value="/")@ResponseBodypublicStringindex(Mapmap){map.put("title","");map.put("keywords","");map.put("description","");return"index";}能不能在方法中控制他返回對(duì)應(yīng)index模型還是返回index字符串就是這2個(gè)合并也就是@ResponseBody能不能只用在其他地方如果是下面這樣,他會(huì)把titlekeywordsdescription直接加在/login/地址欄直接顯示,怎么讓他不顯示,直接就是跳轉(zhuǎn)到/login/java@RequestMapping(value="/")publicStringindex(Mapmap){map.put("title","");map.put("keywords","");map.put("description","");return"redirect:/login/";}
查看完整描述

2 回答

?
楊魅力

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

感覺ResponseEntity可以解決題主的問題,但并不推薦這樣做,下面只是一個(gè)例子。
@RequestMapping("/entity")
@ResponseBody
publicResponseEntityhandle(HttpEntityrequestEntity)throwsUnsupportedEncodingException{
System.out.println(requestEntity.getHeaders().getFirst("MyRequestHeader"));
System.out.println(Arrays.toString(requestEntity.getBody()));
HttpHeadersresponseHeaders=newHttpHeaders();
responseHeaders.set("MyResponseHeader","MyValue");
returnnewResponseEntity<>("HelloWorld",responseHeaders,HttpStatus.CREATED);
}
代碼亂亂的,寫著不順心,改著還鬧心。
不如用headers區(qū)分一下,同一個(gè)URL不同headers映射到不同方法。
比如:
@RequestMapping(value="/",method=RequestMethod.GET,produces=MediaType.APPLICATION_XML_VALUE,headers={"a=1"})
publicStringindex(Mapmap){
map.put("title","");
map.put("keywords","");
map.put("description","");
return"index";
}
@RequestMapping(value="/",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE,headers={"a=1"})
@ResponseBody
publicMapindexJson(Mapmap){
map.put("title","");
map.put("keywords","");
map.put("description","");
returnmap;
}
                            
查看完整回答
反對(duì) 回復(fù) 2019-03-30
?
慕少森

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

應(yīng)該把/login設(shè)置成post請求
                            
查看完整回答
反對(duì) 回復(fù) 2019-03-30
  • 2 回答
  • 0 關(guān)注
  • 374 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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