博客
关于我
Day129.请求数据传入&响应数据传出 -SpringMVC
阅读量:352 次
发布时间:2019-03-04

本文共 2658 字,大约阅读时间需要 8 分钟。

Spring MVC ???????????


??????????

Spring MVC???????????????HTTP???????????????????????????????????????????????????????????

  • @RequestParam????????????????????

    • value???????????
    • required???????????????? true?
    • defaultValue???????????????????
  • @RequestHeader???????????????????????????????????????????????


??@RequestParam????

??????? @RequestParam ????

@RequestMapping(value="/testRequestParam")public String testRequestParam(    @RequestParam(value="username") String username,    @RequestParam(value="age", required=false, defaultValue="0") int age) {    System.out.println("testRequestParam - username=" + username + ", age=" + age);    return "success";}

?????

testRequestParam

??@RequestHeader??

@RequestHeader ??????????????????????

@RequestMapping(value="/testRequestHeader")public String testRequestHeader(    @RequestHeader(value="Accept-Language") String acceptLanguage) {    System.out.println("testRequestHeader - Accept-Language: " + acceptLanguage);    return "success";}

?????

testRequestHeader

??@CookieValue??

@CookieValue ?????????? Cookie ??????????

@RequestMapping("/testCookieValue")public String testCookieValue(    @CookieValue("JSESSIONID") String sessionId) {    System.out.println("testCookieValue: sessionId: " + sessionId);    return "success";}

?????

testCookieValue

????POJO????

Spring MVC???POJO???????????????????????POJO??????????????????

@RequestMapping("/testPojo")public String testPojo(User user) {    System.out.println("testPojo: " + user);    return "success";}

????????

Spring MVC ??????????????????

1. ModelAndView

ModelAndView ???????????????????????? ModelAndView ????????????????

@RequestMapping("/handle04")public ModelAndView handle04() {    ModelAndView mv = new ModelAndView();    mv.setViewName("success0");    mv.addObject("msg", "???");    return mv;}

?????

handle04

2. Map ? Model

???????????? Map ? Model ????????????????????

@RequestMapping("/testMap")public String testMap(Map
map) { map.put("names", Arrays.asList("Tom", "Jerry", "Kite")); return "success";}

?????

testMap

3. SessionAttributes ??

@SessionAttributes ???????????? HttpSession ?????????????

@Controller@SessionAttributes("user")public class SpringMVCController {    @RequestMapping("/testSessionAttributes")    public String testSessionAttributes(Map
map) { User user = new User("Tom", "123", "tom@atguigu.com", 22); map.put("user", user); map.put("school", "atguigu"); return "success"; }}

?????

testSessionAttributes

????

?????????????????Spring MVC ??????????????????????? @RequestParam?@RequestHeader?@CookieValue ????POJO?ModelAndView?Map?SessionAttributes?Spring MVC ????????????

转载地址:http://ucoq.baihongyu.com/

你可能感兴趣的文章
python中的map函数
查看>>
Python中的numpy模块解析
查看>>
Python中的pickle
查看>>
Python中的signal模块和Ctrl+C操作
查看>>
python中的sort方法
查看>>
Python中的threading
查看>>
python中的urlencode和urldecode
查看>>
python中的with学习
查看>>
python中的write和read的用法,有无换行符
查看>>
Python中的“真“和“假“
查看>>
PYTHON中的主体对象标识
查看>>
Python中的修饰函数始终返回NONE
查看>>
Python中的元素相乘与矩阵相乘(附Demo)
查看>>
Python中的分组/聚类数字
查看>>
python中的十六进制字符串到字节数组
查看>>
Python中的单元测试框架:使用unittest进行有效测试
查看>>
Python中的压缩和解压缩模块:zipfile和tarfile
查看>>
python中的变量可以随时命名、随时赋值_python基础2
查看>>
PYTHON中的可变和不可变字符串
查看>>
Python中的多个元组到两对元组?
查看>>