当前位置:网站首页>五、域对象共享数据
五、域对象共享数据
2022-07-26 04:27:00 【时间邮递员】
文章目录
1、使用ServletAPI向request域对象共享数据
index.html
<a th:href="@{/testServletAPI}">testServletAPI</a>
success.html
<p th:text="${testScope}"></p>
@RequestMapping("/testServletAPI")
public String testServletAPI(HttpServletRequest request){
request.setAttribute("testScope", "Hello,ServletAPI");
return "success";
}
2、使用ModelAndView向request域对象共享数据
@RequestMapping("/testModelAndView")
public ModelAndView testModelAndView(){
/** * ModelAndView有Model和View的功能 * Model主要用于向请求域共享数据 * View主要用于设置视图,实现页面跳转 */
ModelAndView mv = new ModelAndView();
//向请求域共享数据
mv.addObject("testModelAndView", "Hello,ModelAndView");
//设置视图,实现页面跳转
mv.setViewName("success");
return mv;
}
3、使用Model向request域对象共享数据
@RequestMapping("/testModel")
public String testModel(Model model){
model.addAttribute("testModel", "Hello,Model");
return "success";
}
4、使用map向request域对象共享数据
@RequestMapping("/testMap")
public String testMap(Map<String, Object> map){
map.put("testMap", "Hello,Map");
return "success";
}
5、使用ModelMap向request域对象共享数据
@RequestMapping("/testModelMap")
public String testModelMap(ModelMap modelMap){
modelMap.addAttribute("testScope", "Hello,ModelMap");
return "success";
}
6、Model、ModelMap、Map的关系
Model、ModelMap、Map类型的参数本质上都是 BindingAwareModelMap 类型的
public interface Model{
}
public class ModelMap extends LinkedHashMap<String, Object> {
}
public class ExtendedModelMap extends ModelMap implements Model {
}
public class BindingAwareModelMap extends ExtendedModelMap {
}
7、向session域共享数据
<p th:text="${session.testScope}"></p>
@RequestMapping("/testModelMap")
public String testModelMap(ModelMap modelMap){
modelMap.addAttribute("testScope", "Hello,ModelMap");
return "success";
}
@RequestMapping("/testSession")
public String testSession(HttpSession session){
session.setAttribute("testScope", "Hello,Session");
return "success";
}
8、向application域共享数据
<p th:text="${application.testApplicationScope}"></p>
@RequestMapping("/testApplication")
public String testApplication(HttpSession session){
ServletContext application = session.getServletContext();
application.setAttribute("testApplicationScope", "Hello,Application");
return "success";
}
边栏推荐
- [binary tree] the longest interleaved path in a binary tree
- egg-ts-sequelize-CLI
- How does win11 set the theme color of the status bar? Win11 method of setting theme color of status bar
- Build a maker Education Laboratory for teenagers
- MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection
- 数组排序3
- egg-sequelize JS编写
- The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
- Compiled by egg serialize JS
- HelloWorld case analysis
猜你喜欢

The auxiliary role of rational cognitive educational robot in teaching and entertainment

Apisex's exploration in the field of API and microservices

Design and implementation of smart campus applet based on cloud development

Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200

Support proxy direct connection to Oracle database, jumpserver fortress v2.24.0 release

Steam科学教育赋予课堂教学的创造力

1. Mx6u system migration-6-uboot graphical configuration

Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service

1. Mx6u-alpha development board (main frequency and clock configuration experiment)

Keil V5 installation and use
随机推荐
P-norm (2-norm is Euclidean norm)
How to download the supplementary literature?
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
Acwing brush questions
Makefile knowledge rearrangement (super detailed)
图互译模型
How does win11 set the theme color of the status bar? Win11 method of setting theme color of status bar
Web Test Method Encyclopedia
The auxiliary role of rational cognitive educational robot in teaching and entertainment
Soft simulation rasterization renderer
dijango学习
VM virtual machine has no un bridged host network adapter, unable to restore the default configuration
建设面向青少年的创客教育实验室
Yadi started to slow down after high-end
How to write the introduction and conclusion of an overview paper?
Chapter 3 how to use sourcetree to submit code
Recommendation Book Educational Psychology: a book for tomorrow's teachers~
旋转数组最小数字
[learning notes] agc041
Life related - ten years of career experience (turn)