当前位置:网站首页>五、域对象共享数据
五、域对象共享数据
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";
}
边栏推荐
- 雅迪高端之后开始变慢
- 旋转数组最小数字
- 低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!
- Huawei issued another global convening order of "genius youth", and some people once gave up their annual salary of 3.6 million to join
- 1. Mx6u-alpha development board (GPIO interrupt experiment)
- Weights & Biases (二)
- qt编译报错整理及Remote模块下载
- MySQL only checks the reasons for the slow execution of one line statements
- What are the consequences and problems of computer system restoration
- Credit card fraud detection based on machine learning
猜你喜欢

吴恩达机器学习课后习题——线性回归

综合评价与决策方法

Creative design principle of youth maker Education

makefile知识再整理(超详细)

Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!

当你尝试删除程序中所有烂代码时 | 每日趣闻
![[C language foundation] 13 preprocessor](/img/4c/ab25d88e9a0cf29bde6e33a2b14225.jpg)
[C language foundation] 13 preprocessor

Credit card fraud detection based on machine learning

FFmpeg 视频添加水印

生活相关——十年的职业历程(转)
随机推荐
[SVN] please execute the 'cleanup' command appears all the time. The solution is that there is no response after cleanup
View and modify the number of database connections
Steam科学教育赋予课堂教学的创造力
egg-ts-sequelize-CLI
Postman 导入curl 、导出成curl、导出成对应语言代码
人脸数据库收集总结
红星美凯龙高负债之下,盯上新能源了?
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
数据仓库
Recognized again | saining network security has been listed in the ccsip 2022 panorama of China's network security industry
支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布
Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
Acwing_ 12. Find a specific solution for the knapsack problem_ dp
Under the high debt of Red Star Macalline, is it eyeing new energy?
1. Mx6u system migration-6-uboot graphical configuration
香甜的黄油
egg-sequelize JS编写
Web Test Method Encyclopedia
ROS2的launch有何不同?
MySQL日志分类:错误日志、二进制日志、查询日志、慢查询日志