当前位置:网站首页>五、域对象共享数据
五、域对象共享数据
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";
}
边栏推荐
- Which websites can I visit to check the latest medical literature?
- What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
- Life related - ten years of career experience (turn)
- Credit card fraud detection based on machine learning
- 1. If function of Excel
- 机器学习之桑基图(用于用户行为分析)
- 综合评价与决策方法
- The auxiliary role of rational cognitive educational robot in teaching and entertainment
- Li Kou daily question - day 42 -661. Picture smoother
- egg-ts-sequelize-CLI
猜你喜欢

Firewall command simple operation
Yuansaka Lin wallpaper

Wu Enda's machine learning after class exercises - logical regression

UE4 键盘控制开关灯

What are the consequences and problems of computer system restoration

MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection

Creative design principle of youth maker Education

ASP. Net core actionfilter filter details

p-范数(2-范数 即 欧几里得范数)

Credit card fraud detection based on machine learning
随机推荐
数据库连接数查看和修改
p-范数(2-范数 即 欧几里得范数)
Optimization analysis and efficiency execution of MySQL
Credit card fraud detection based on machine learning
What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
Unable to find sygwin.s file during vscode debugging
Web Test Method Encyclopedia
MySQL log classification: error log, binary log, query log, slow query log
When you try to delete all bad code in the program | daily anecdotes
UE4 多个角色控制权的切换
Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?
dijango学习
Chapter 3 how to use sourcetree to submit code
Day26 job
Use of anonymous functions
Graph theory: topological sorting
AWS Support Plan
MapReduce中分区数与ReduceTask个数关系比较
Postman 导入curl 、导出成curl、导出成对应语言代码
[C language foundation] 13 preprocessor