zoukankan      html  css  js  c++  java
  • 【原创】SpringMVC同一RequestMapping返回不同的类型

    曾经在工作中遇到过导出文件时,需要根据不同情况返回不同的数据的情况。
    例如:

    1. 如果没有数据,弹框提示“没有数据”
    2. 导出报错,弹框提示“系统错误”
    3. 正常情况下,下载文件
      也就是说需要在不同的情况下响应不同的返回消息.

        @RequestMapping("/totalPlan")
        @ResponseBody
        public R test(HttpServletRequest request, HttpServletResponse response, String code) throws IOException, ServletException {
        	if("json".equals(code)) {
        		R r = new R();
        		return r;
        	} else if("page".equals(code)) {
        		response.sendRedirect(request.getContextPath() + "/user.html");
        		return null;
        	} else if("file".equals(code))  {
        		request.getRequestDispatcher("").forward(request, response);
        	}
        	...
       }
    
  • 相关阅读:
    Shiro权限验证
    5种设计模式整理
    多模块的SpringBoot项目
    Go使用数据库
    使用Go mod
    docker基本使用
    Go的IO操作
    实现一个网盘存储……
    Go的网络编程
    学习golang的历程
  • 原文地址:https://www.cnblogs.com/Candies/p/8533766.html
Copyright © 2011-2022 走看看