大一统controller

xiaoxiao2021-02-28  14

package com.ibaby.application.system.controller; import java.lang.reflect.Method; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.ibaby.application.system.service.AnalysisService; import com.ibaby.framework.mapper.JsonMapper; import com.ibaby.framework.utils.StringUtils; import com.ibaby.framework.web.BaseController; /** * 通用的数据分析控制器,用于简单的访问路径对文件路径的匹配 * @author cuibei * */ @Controller @RequestMapping(value="/analysis") public class AnalysisController extends BaseController{ @Autowired private AnalysisService analysisService; @SuppressWarnings({ "rawtypes", "unchecked" }) @RequestMapping(value="/{level1}/{level2}/{level3}",method=RequestMethod.GET) public String level(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model model , @PathVariable(value = "level1") String level1 , @PathVariable(value = "level2") String level2 , @PathVariable(value = "level3") String level3){ //根据请求路径生成相应的业务方法,如果存在则调用 String methodName = level1 + StringUtils.upperFirst(level2) + StringUtils.upperFirst(level3); Class serviceClass = analysisService.getClass(); try { Method m = serviceClass.getMethod(methodName, HttpServletRequest.class,Model.class); m.invoke(analysisService, request, model); } catch (Exception e) { } //将请求的参数传递给jsp页面,使用方法:如参数名叫canshu,则写法为${request.canshu[0] } Map requestMap = request.getParameterMap(); model.addAttribute("request", requestMap); //将请求的参数传递给js文件,使用方法:如参数名叫canshu,则写法为request.canshu[0] model.addAttribute("requestJson", JsonMapper.toJsonString(requestMap)); return "analysis/"+level1+"/"+level2+"/"+level3; } }
转载请注明原文地址: https://www.6miu.com/read-2500265.html

最新回复(0)