这个是直接对应 index
模型
java
@RequestMapping(value = "/") public String index(Map<String, Object> map) { map.put("title", ""); map.put("keywords", ""); map.put("description", ""); return "index"; }
这个是直接返回 index
字符串
java
@RequestMapping(value = "/") @ResponseBody public String index(Map<String, Object> map) { map.put("title", ""); map.put("keywords", ""); map.put("description", ""); return "index"; }
能不能在方法中控制他返回对应 index
模型还是返回 index
字符串
就是这2个合并
也就是 @ResponseBody
能不能只用在其他地方
如果是下面这样,他会把 title
keywords
description
直接加在 /login/
地址栏直接显示,怎么让他不显示,直接就是 跳转到 /login/
java
@RequestMapping(value = "/") public String index(Map<String, Object> map) { map.put("title", ""); map.put("keywords", ""); map.put("description", ""); return "redirect:/login/"; }
I feel that ResponseEntity can solve the problem of the subject, but it is not recommended. The following is just an example.
The code is messy, the writing is not satisfactory, and it is annoying to change it.
It is better to use headers to differentiate. Different headers of the same URL map to different methods.
For example:
/login should be set as post request