博客
关于我
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 | fire,一个强大的 Python 库!
查看>>
python | flanker,一个神奇的 Python 库!
查看>>
python | flower,一个强大的 Python 库!
查看>>
python | funcy,一个超强的 提供函数式编程工具 Python 库!
查看>>
python | ggplot,一个超强的 Python 库!
查看>>
python | grab,一个强大的 Python 库!
查看>>
python | gunicorn,一个非常实用的 Python 库!
查看>>
python | h5py,一个无敌的关于 HDF5 的 Python 库!
查看>>
python | huey,一个非常厉害的 任务调度 Python 库!
查看>>
python | hypothesis,一个有趣的 Python 库!
查看>>
python | Indico,一个超酷的 Python 库!
查看>>
python | isort,一个有趣的 自动整理导入语句 的Python 库!
查看>>
python | jinja,一个超酷的 Python 库!
查看>>
python | joblib,一个强大的 Python 库!
查看>>
python调用git bash_Python学习第70课-用Git Bash在命令行打开sublime
查看>>
python | jsonschema,一个实用的 验证 JSON 数据结构 Python 库!
查看>>
python课程的中期报告范文_课题研究中期总结报告范文
查看>>
python | lxml,一个超酷的 关于XML/HTML 文档 Python 库!
查看>>
python | mplfinance,一个有趣的金融数据可视化 Python 库!
查看>>
python | nipy,一个强大的关于 神经影像数据分析 的Python 库!
查看>>