更新404页面,改为不渲染json,渲染html页面

pull/65/head
fengshuonan 2021-01-02 10:29:52 +08:00
parent 891e4e3f94
commit aeefbfb84d
2 changed files with 9 additions and 19 deletions

View File

@ -1,5 +1,6 @@
package cn.stylefeng.guns.config.web; package cn.stylefeng.guns.config.web;
import cn.stylefeng.guns.core.beetl.CustomBeetlGroupUtilConfiguration;
import cn.stylefeng.guns.core.error.CustomErrorAttributes; import cn.stylefeng.guns.core.error.CustomErrorAttributes;
import cn.stylefeng.guns.core.error.CustomErrorView; import cn.stylefeng.guns.core.error.CustomErrorView;
import cn.stylefeng.guns.core.security.AuthJwtTokenSecurityInterceptor; import cn.stylefeng.guns.core.security.AuthJwtTokenSecurityInterceptor;
@ -60,8 +61,11 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
* @date 2020/12/16 15:47 * @date 2020/12/16 15:47
*/ */
@Bean("error") @Bean("error")
public CustomErrorView error() { public CustomErrorView error(CustomBeetlGroupUtilConfiguration customBeetlGroupUtilConfiguration) {
return new CustomErrorView(); CustomErrorView customErrorView = new CustomErrorView();
customErrorView.setUrl("/404.html");
customErrorView.setGroupTemplate(customBeetlGroupUtilConfiguration.getGroupTemplate());
return customErrorView;
} }
/** /**

View File

@ -1,14 +1,6 @@
package cn.stylefeng.guns.core.error; package cn.stylefeng.guns.core.error;
import cn.hutool.core.bean.BeanUtil; import org.beetl.ext.spring.BeetlSpringView;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.util.ResponseRenderUtil;
import org.springframework.web.servlet.View;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/** /**
* (404,) * (404,)
@ -16,17 +8,11 @@ import java.util.Map;
* @author fengshuonan * @author fengshuonan
* @date 2017-05-21 11:34 * @date 2017-05-21 11:34
*/ */
public class CustomErrorView implements View { public class CustomErrorView extends BeetlSpringView {
@Override @Override
public String getContentType() { public String getContentType() {
return "text/html"; return "text/html;charset=UTF-8";
}
@Override
public void render(Map<String, ?> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ErrorResponseData errorResponseData = BeanUtil.mapToBean(map, ErrorResponseData.class, true, CopyOptions.create().ignoreError());
ResponseRenderUtil.renderErrorResponse(httpServletResponse, errorResponseData.getCode(), errorResponseData.getMessage(), errorResponseData.getExceptionClazz());
} }
} }