数据的处理
Posted alloevil
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据的处理相关的知识,希望对你有一定的参考价值。
1 提交数据的处理
a提交的域名城和处理方法的参数名一致即可
提交的数据
处理方法
@RequestMapping("/hello") public String hello(String name){ System.out.println(name); return "index.jsp"; //这种方式不需要视图解析器 }
b如果域名城和参数名不一致
提交的数据
处理方法
@RequestMapping("/hello") public String hello(@RequestParam("uname")String name){ System.out.println(name); return "index.jsp"; //这种方式不需要视图解析器 }
c提交一个对象
要求提交的表单域名和对象的属性名一致,参数使用对象即可
处理方法
@RequestMapping("/user") public String user(User user){ System.out.println(user); return "index.jsp"; }
实体类
package com.sgcc.entity; public class User { private int id; private String name; private String pwd; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } @Override public String toString() { return "User [id=" + id + ", name=" + name + ", pwd=" + pwd + "]"; } }
2 将数据显示到ui层
第一种通过ModelAndView 需要通过视图解析器
第二种通过ModelMap来实现 不需要通过视图解析器
ModelMap需要作为处理方法的参数
@RequestMapping("/hello") public String hello(@RequestParam("uname")String name,ModelMap model){ //相当于request.setAttribute("name",name); model.addAttribute("name", name); System.out.println(name); return "index.jsp"; //这种方式不需要视图解析器 }
ModelAndView 和ModelMap的区别
相同点都可以将数据封装显示到表示层页面中
不同ModelAndView 可以指定跳转到视图,而ModelMap不能
ModelAndView 需要视图解析器 ModelMap不需要配置
以上是关于数据的处理的主要内容,如果未能解决你的问题,请参考以下文章
在 Python 多处理进程中运行较慢的 OpenCV 代码片段
Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理(代码片段
你如何在 python 中处理 graphql 查询和片段?