加入自定义404与error界面

This commit is contained in:
Saturneric 2020-02-14 18:10:02 +08:00
parent e34f87b01c
commit 18050e037f
8 changed files with 47 additions and 19 deletions

View File

@ -111,7 +111,7 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.16.10</version> <version>1.16.10</version>
</dependency>s </dependency>
</dependencies> </dependencies>

View File

@ -2,7 +2,6 @@ package com.codesdream.ase;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication @SpringBootApplication
public class AseApplication { public class AseApplication {

View File

@ -0,0 +1,30 @@
package com.codesdream.ase.controller;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
@Controller
public class ASEErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(HttpServletRequest request, Model model){
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
// 页面未找到
if(statusCode == 404){
return "not_found";
}
return"error";
}
@Override
public String getErrorPath() {
return "/error";
}
}

View File

@ -29,4 +29,10 @@ public class UserDetail {
// 所属专业 // 所属专业
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private BaseMajor baseMajor; private BaseMajor baseMajor;
// 真实姓名
private String realName;
// 学生ID
private String studentID;
} }

View File

@ -34,14 +34,14 @@ public class UserService implements IUserService {
@Override @Override
public User save(User user) { public User save(User user) {
// 查找用户名是否已经被注册
if(userRepository.findByUsername(user.getUsername()).isPresent()) if(userRepository.findByUsername(user.getUsername()).isPresent())
throw new RuntimeException("Username Already Exists"); throw new RuntimeException("Username Already Exists");
user.setPassword(asePasswordEncoder.encode(user.getPassword())); user.setPassword(asePasswordEncoder.encode(user.getPassword()));
user.setEnabled(true);
user.setDeleted(false);
return userRepository.save(user); return userRepository.save(user);
} }
// 获得一个默认初始化的用户对象
@Override @Override
public User getDefaultUser() { public User getDefaultUser() {
return new User(); return new User();

View File

@ -7,7 +7,7 @@ spring.thymeleaf.encoding=UTF-8
spring.jpa.generate-ddl=false spring.jpa.generate-ddl=false
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create spring.jpa.hibernate.ddl-auto=update
spring.jooq.sql-dialect=org.hibernate.dialect.MySQL5InnoDBDialect spring.jooq.sql-dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.open-in-view=true spring.jpa.open-in-view=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
@ -15,3 +15,6 @@ spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:119.23.9.34}:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC spring.datasource.url=jdbc:mysql://${MYSQL_HOST:119.23.9.34}:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=codedream spring.datasource.username=codedream
spring.datasource.password=codedreampasswd spring.datasource.password=codedreampasswd
server.error.whitelabel.enabled=false

View File

@ -1,12 +1,7 @@
<!doctype html> <!doctype html>
<html> <html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head> <head>
<link href="../static/assets/css/atlantis.css" rel="stylesheet" type="text/css" media="screen">
<link href="../static/assets/css/atlantis.css.map.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/atlantis.min.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/demo.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/fonts.css" rel="stylesheet" type="text/css"><link href="../static/assets/css/fonts.min.css" rel="stylesheet" type="text/css">
<div th:include="layout::head"></div> <div th:include="layout::head"></div>
<meta charset="utf-8"> <meta charset="utf-8">
<title>error</title> <title>error</title>

View File

@ -1,12 +1,7 @@
<!doctype html> <!doctype html>
<html> <html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head> <head>
<link href="../static/assets/css/atlantis.css" rel="stylesheet" type="text/css" media="screen">
<link href="../static/assets/css/atlantis.css.map.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/atlantis.min.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/demo.css" rel="stylesheet" type="text/css">
<link href="../static/assets/css/fonts.css" rel="stylesheet" type="text/css"><link href="../static/assets/css/fonts.min.css" rel="stylesheet" type="text/css">
<div th:include="layout::head"></div> <div th:include="layout::head"></div>
<meta charset="utf-8"> <meta charset="utf-8">
<title>notfound</title> <title>notfound</title>