zoukankan      html  css  js  c++  java
  • spring_response

    package com.zl.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    //@ResponseBody
    //@RestController //@Controller+@ResponseBody
    public class HanderController {
        /*@RequestMapping("/hello")
        public String hello() {
            System.out.println("hello");
            return "success";
    
        }*/
        //如果返回值为void,此时会跳转到 prefix+uri+suffix 对应的页面
        /*@RequestMapping("/void")
        public void hello(HttpServletResponse response, HttpServletRequest request) throws Exception {   //跳转到 WEB-INF/pages/void.jsp
            System.out.println("hello-void");
            //response.getWriter().write("zs");  //加上之后,使得请求乱码了???
            response.sendRedirect("http://www.baidu.com");
            //request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request, response);
        }*/
        /*@RequestMapping("/mv")
        public ModelAndView mvhander() {
            System.out.println("mv");
            ModelAndView mv = new ModelAndView();  //创建一个ModelAndView
            //往ModelAndView中封装数据
            User user = new User();
            user.setName("zs");
            user.setAge(23);
            mv.addObject("user", user);
    
            mv.setViewName("success");  //设置视图名字。success-success.jsp
            return mv;
        }*/
        //SpringMVC自身也提供了转发和重定向,不论是转发还是重定向,返回类型都为String,但返回的String都需要在前面加上特殊字符。
        /*@RequestMapping("/mv")
        public String hander() {
            System.out.println("hello");
            //return "redirect:http://www.baidu.com";
            return "forward:/WEB-INF/pages/succ0ess.jsp";  //转发不能使用视图解析器的前缀和后缀,必须写页面完整路径.不然与return有冲突
        }*/
        /*@RequestMapping("/json")
        @ResponseBody //也可作用于类
        public User handler(@RequestBody User user) { //RequestBody-json-jackson-userduixiang
            System.out.println(user);
            user.setName("gd");
            return user;
        }*/
    
        /*//自定义异常
        @RequestMapping("/error")
        public String error() {
            System.out.println("hello");
            System.out.println(10/0);
            return "success";
        }*/
        @RequestMapping("hello")
        public String hello() throws InterruptedException {
            Thread.sleep(3000);
            System.out.println("目标方法");
            Thread.sleep(3000);
            return "success";
        }
    }
  • 相关阅读:
    Wannafly #4 F 线路规划
    PKUWC2018 随机算法
    noip模拟赛
    php 正则判断是否是手机号码 最新
    Onethink上传服务器后登录不了的问题
    【php中的curl】php中curl的详细解说
    50种网站引流量方式
    mysql ERROR 1045 (28000): 错误解决办法
    织梦DEDE分类信息实现联动筛选(支持多条件多级选项)解决方案
    dedecms新增联动类别后的使用方法
  • 原文地址:https://www.cnblogs.com/21556guo/p/13761832.html
Copyright © 2011-2022 走看看