ja开发新之SpringBoot转发和重定向
来源:设计 2024年10月23日 12:16
public String test3(RedirectAttributes redirectAttributes) {
redirectAttributes.addAttribute("name", "碰巧");
redirectAttributes.addAttribute("age", 30);
return "redirect:/redirect/test4";
}
@RequestMapping(value = "/redirect/test4", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map test4(@RequestParam("name") String name, @RequestParam("age") int age) {
Map result = new LinkedHashMap<>();
result.put("name", name);
result.put("age", age);
return result;
}
测试者缺点JaScript中都采访/redirect/test3连接器,亦会被链接到/redirect/test4,缺点如下,test3 新方法中都碰到到addAttribute中都的 2 个数取值name和age,被启动时堆砌到IP上去了。
3.5、链接传参方式为 2:RedirectAttributes.addFlashAttribute("数取值","取值")里面我们适用的是RedirectAttributes的addAttribute放入数取值,这次我们要适用另外一个新方法addFlashAttribute放入链接须要传送的数取值,具体内容有什么区别于呢,请向下看。
名词 连接器中都须要有一个子类为RedirectAttributes的数取值 线程redirectAttributes.addFlashAttribute("数取值","取值"),这种方式为传送的数取值是被隐秘的,不亦会被堆砌在IP后,实质上是通过 session 构建统计数据来构建的。 被链接到的连接器,须要适用一个org.springframework.ui.Model或者org.springframework.ui.ModelMap子类的数取值来接收传送过来的数取值,线程model.getAttribute("数取值名")可以获取传送过来的数取值 近来code 采访连接器 test5,亦会被链接到 test6,悄悄传送了 2 个数取值@RequestMapping("/redirect/test5")
public String test5(RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("name", "碰巧");
redirectAttributes.addFlashAttribute("age", 30);
return "redirect:/redirect/test6";
}
/**
* 须要适用一个org.springframework.ui.Model或者org.springframework.ui.ModelMap子类的数取值来接收传送过来的数取值,
* 新方法实质上线程model.getAttribute("数取值名")可以获取传送过来的数取值
* @param model
* @return
*/
@RequestMapping(value = "/redirect/test6", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map test6(Model model) {
String name = (String) model.getAttribute("name");
Integer age = (Integer) model.getAttribute("age");
Map result = new LinkedHashMap<>();
result.put("name", name);
result.put("age", age);
return result;
}
测试者缺点JaScript中都采访/redirect/test5连接器,亦会被链接到/redirect/test6,缺点如下,数取值传送事与愿违了,传送是隐秘式的。
原理redirectAttributes.addFlashAttribute 放入链接须要传送的数取值,SpringMVC 在链接到从新IP之后,亦会将这部分统计数据碰到到 session 中都,当链接的恳请过来后,SpringMVC 又亦会从 session 中都拿到这部分统计数据,然后碰到到 Model 或者 ModelMap 中都,然后冲 session 中都搬运掉这部分统计数据。
3.6、RedirectAttributes.addAttribute 和 RedirectAttributes.addFlashAttribute 区别于 都可以构建链接传送数取值 addAttribute 传送的数取值,最后亦会附带在从重新IP上,而 addFlashAttribute 传送的数取值是隐秘式的 addFlashAttribute 可以传送大量的信息,不过 addFlashAttribute 有个弊端,链接到从新IP之后,如下布,如果此时用户刷从新页面,传送的数取值取不到了,就碰到失了,劝告适用方式为 1 和方式为 2;方式为 3 可以作为明白。 4、近来code git IP 4.1、git IP 4.2、本文近来code结构说明社论比如说:碰巧甲Ja
推荐阅读:
Springboot如何适用Aspect来构建切面笔记
前端技术开发SpringBoot之连接器文档的生成
ja技术开发之SpringBoot构建启动时执行code
。苏州苹果手机官方售后健胃消食片
太极藿香正气口服液
养生医药资讯
昆明妇科哪家医院最好
家用血糖仪怎么选
胃酸过多怎么治疗
抑制胃酸用金奥康可以吗
用什么方法可以有效的抵抗衰老
脂肪肝中药配方
-
未成年人入住电竞酒店抽烟上网不依赖于?媒体:管理乱象何时休
月底,针对网友反映“未满成群结队通过留宿铁子第二场技饭店的方式将另类APP,在进去吸烟、APP等全然不受限制”的留言,山东省科罗拉多州市委督查室回复称,省级未全面实施就其政策文档明确铁子第二场技饭店性