zoukankan      html  css  js  c++  java
  • 2021-5-5 日报博客

    个人博客

    1.学到的东西

    04-SpringMVC的数据响应-页面跳转-返回ModelAndView形式2(应用)

    n在Controller中方法形参上直接声明ModelAndView,无需在方法中自己创建,在方法中直接使用该对象设置视图,同样可以跳转页面

     @RequestMapping(value="/quick3")
        public ModelAndView save3(ModelAndView modelAndView){
            modelAndView.addObject("username","itheima");
            modelAndView.setViewName("success");
            return modelAndView;
        }
    @RequestMapping(value="/quick4")
        public String save4(Model model){
            model.addAttribute("username","博学谷");
            return "success";
        }
    

    05-SpringMVC的数据响应-页面跳转-返回ModelAndView3(应用)

    在Controller方法的形参上可以直接使用原生的HttpServeltRequest对象,只需声明即可

    @RequestMapping(value="/quick5")
        public String save5(HttpServletRequest request){
            request.setAttribute("username","酷丁鱼");
            return "success";
        }
    

    06-SpringMVC的数据响应-回写数据-直接回写字符串(应用)

    通过SpringMVC框架注入的response对象,使用response.getWriter().print(“hello world”) 回写数据,此时不需要视图跳转,业务方法返回值为void

    将需要回写的字符串直接返回,但此时需要通过@ResponseBody注解告知SpringMVC框架,方法返回的字符串不是跳转是直接在http响应体中返回

    @RequestMapping(value="/quick7")
        @ResponseBody  //告知SpringMVC框架 不进行视图跳转 直接进行数据响应
        public String save7() throws IOException {
            return "hello itheima";
        }
    
        @RequestMapping(value="/quick6")
        public void save6(HttpServletResponse response) throws IOException {
            response.getWriter().print("hello itcast");
        }
    

    2.明日计划

    学习其他数据响应的方式。

    3.遇到的问题

  • 相关阅读:
    SQL怎么随机提取出一条信息 mysql 获取随机记录
    css3 渐变 各浏览器兼容
    php的curl和socket的区别 转
    php获取本机真实IP地址
    SSH超时断开 ssh 老掉线
    php 获取远程服务器信息 get_headers 的使用
    如何删除右键菜单中的Catalyst(TM) Control Center选项
    多线程概念、案例!
    网络编程
    我的博客开通啦
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/14912160.html
Copyright © 2011-2022 走看看