标签:bind pst check 函数 text new work 为知笔记 date
package com.haramasu.daomin2.error;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.Map;
/**
* @Auther: DingShuo
* @Date: 2018/7/23 12:25
* @Description:
*/
@Controller
@RequestMapping(value = "/error")
public class MyBasicErrorController extends BasicErrorController {
Logger logger =LoggerFactory.getLogger(MyBasicErrorController.class);
public MyBasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) {
super(errorAttributes, errorProperties);
}
@Override
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
HttpStatus status = getStatus(request);
Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
request, isIncludeStackTrace(request, MediaType.TEXT_HTML)));
response.setStatus(status.value());
ModelAndView modelAndView = resolveErrorView(request, response, status, model);
if(modelAndView!=null){
return modelAndView;
}else {
String path=model.get("path").toString();
logger.debug("该地址无法访问:"+path);
if(path.startsWith("/admin/")){
return new ModelAndView("error/adminError", model);
}else {
return new ModelAndView("error/homeError", model);
}
}
}
}
package com.haramasu.daomin2.error;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.Map;
/**
* @Auther: DingShuo
* @Date: 2018/7/23 12:25
* @Description:
*/
@Controller
@RequestMapping(value = "/error")
public class MyBasicErrorController extends BasicErrorController {
Logger logger =LoggerFactory.getLogger(MyBasicErrorController.class);
public MyBasicErrorController(ErrorAttributes errorAttributes, ErrorProperties errorProperties) {
super(errorAttributes, errorProperties);
}
@Override
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
HttpStatus status = getStatus(request);
Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(
request, isIncludeStackTrace(request, MediaType.TEXT_HTML)));
response.setStatus(status.value());
ModelAndView modelAndView = resolveErrorView(request, response, status, model);
if(modelAndView!=null){
return modelAndView;
}else {
String path=model.get("path").toString();
logger.debug("该地址无法访问:"+path);
if(path.startsWith("/admin/")){
return new ModelAndView("error/adminError", model);
}else {
return new ModelAndView("error/homeError", model);
}
}
}
}
package com.haramasu.daomin2.conf;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Auther: DingShuo
* @Date: 2018/7/23 12:08
* @Description:
*/
@Configuration
public class BeanConfig {
@Bean
public ErrorProperties errorProperties(){
return new ErrorProperties();
}
}
package com.haramasu.daomin2.conf;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Auther: DingShuo
* @Date: 2018/7/23 12:08
* @Description:
*/
@Configuration
public class BeanConfig {
@Bean
public ErrorProperties errorProperties(){
return new ErrorProperties();
}
}
标签:bind pst check 函数 text new work 为知笔记 date
原文地址:https://www.cnblogs.com/tilv37/p/9354137.html