Skip to content

Commit

Permalink
发布预览版,优化页面效果,去掉 ErrorPageController
Browse files Browse the repository at this point in the history
  • Loading branch information
fengwenyi committed Jun 5, 2019
1 parent 0d5ff14 commit e1d870e
Show file tree
Hide file tree
Showing 25 changed files with 448 additions and 251 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

333 changes: 291 additions & 42 deletions .idea/workspace.xml

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

[![](https://jitpack.io/v/iutil/app-boot-starter.svg)](https://jitpack.io/#iutil/app-boot-starter)


<h1 align="center">
App Boot Starter
</h1>
Expand All @@ -11,6 +8,9 @@
</p>

<p align="center">
<a target="_blank" href="https://jitpack.io/#iutil/app-boot-starter">
<img src="https://jitpack.io/v/iutil/app-boot-starter.svg" ></img>
</a>
<a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.html">
<img src="https://img.shields.io/:license-apache-blue.svg" ></img>
</a>
Expand All @@ -36,6 +36,10 @@
只为下一个应用,
一个引入,就可以解决这些问题。

## 预览

![404 页面 预览效果](./images/404.png)

## 使用

你只需要两步,即可使用:
Expand All @@ -57,7 +61,7 @@
<dependency>
<groupId>com.github.iutil</groupId>
<artifactId>app-boot-starter</artifactId>
<version>1.0.0.BUILD</version>
<version>1.0.0.SNAPSHOT</version>
</dependency>
```

Expand All @@ -77,10 +81,14 @@
.
└── src
    └── resources
   ├── static
   │   └── css
   │   └── error
   │   └── style.css // 样式
    └── templates
    └── error
    ├── 404.html
    ├── 500.html
    └── error.html
    ├── 404.html // 404页面
    ├── 500.html // 500页面
    └── error.html // 错误页面
```

7 changes: 6 additions & 1 deletion app-boot-starter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.1.7.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.1.7.RELEASE" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.6.2" level="project" />
<orderEntry type="library" name="Maven: com.github.fengwenyi:JavaLib-result:V1.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:2.1.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf:3.0.11.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.attoparser:attoparser:2.0.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.6.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.4.RELEASE" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.iutil:api-result:1.0.0.BUILD" level="project" />
</component>
<component name="copyright">
<Base>
<setting name="state" value="2" />
</Base>
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.iutil.app.boot.starter;

import com.fengwenyi.javalib.result.Result;
import net.iutil.ApiResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -12,8 +13,10 @@
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

/**
* controller 错误处理
* @author Erwin Feng
* @since 2019-05-24 16:56
*/
Expand All @@ -32,30 +35,44 @@ public class ErrorPageController implements ErrorController {
/* view error */
private static final String VIEW_ERROR = "error/error";

@Value("${app.version}")
private String version;

@Value("${spring.application.name}")
private String appName;

@RequestMapping(value = ERROR_PATH, produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView handleError(HttpServletRequest request,
HttpServletResponse response) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);

ModelAndView mv = new ModelAndView();
mv.addObject("year", LocalDate.now().getYear());
mv.addObject("version", version);
mv.addObject("appName", appName);

if (status != null) {
int statusCode = Integer.valueOf(status.toString());

if(statusCode == HttpStatus.NOT_FOUND.value()) {
return new ModelAndView(VIEW_404);
mv.setViewName(VIEW_404);
return mv;
}

else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
return new ModelAndView(VIEW_500);
mv.setViewName(VIEW_500);
return mv;
}
}
return new ModelAndView(VIEW_ERROR);
mv.setViewName(VIEW_ERROR);
return mv;
}

@RequestMapping(value = ERROR_PATH)
@ResponseBody
public Result handleErrorJson(HttpServletRequest request,
HttpServletResponse response) {
return Result.error();
public ApiResult handleErrorJson(HttpServletRequest request,
HttpServletResponse response) {
return ApiResult.error();
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions bak/version_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```html
Copyright &copy;<span th:text="${year}"></span>
<span th:text="${appName}"></span>
V<span th:text="${version}"></span>
```
Binary file added images/404.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

<groupId>net.iutil</groupId>
<artifactId>app-boot-starter</artifactId>
<version>1.0.0.BUILD</version>
<version>1.0.0.SNAPSHOT</version>
<packaging>jar</packaging>
<name>app-boot-starter</name>
<description>应用起步</description>

Expand All @@ -33,16 +34,17 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.fengwenyi</groupId>
<artifactId>JavaLib-result</artifactId>
<version>V1.1.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!--<dependency>
<groupId>com.github.iutil</groupId>
<artifactId>api-result</artifactId>
<version>1.0.0.BUILD</version>
<scope>provided</scope>
</dependency>-->
</dependencies>

<build>
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/resources/.DS_Store
Binary file not shown.
29 changes: 29 additions & 0 deletions src/main/resources/static/css/error/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
* {
margin: 0;
padding: 0;
}
body {
background-color: #eee;
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.home {
width: 300px;
height: 180px;
line-height: 180px;
margin: 100px auto 0;
background-color: #333;
color: #e3e3e3;
text-align: center;
font-size: 60px;
border: 0;
border-radius: 5px;
box-shadow: 0 0 80px #333;
}
.footer {
text-align: center;
margin-top: 30px;
color: #aaa;
font-size: 12px;
}
Binary file added src/main/resources/templates/.DS_Store
Binary file not shown.
36 changes: 10 additions & 26 deletions src/main/resources/templates/error/404.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>404 View</title>

<title>404</title>
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta name="description" content="This is error view" />
<meta name="description" content="This is 404 view" />
<meta name="author" content="Erwin Feng" />

<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #eee;
}
.home {
width: 300px;
height: 125px;
background-color: #333;
color: #eee;
text-align: center;
padding-top: 50px;
font-size: 50px;
border-radius: 5px;
margin: 100px auto 0;
}
</style>
<link rel="stylesheet" href="/css/error/style.css">
</head>
<body>
<div class="home">
<section class="home">
404
</div>
</section>

<footer class="footer">
Copyright &copy;2019
</footer>
</body>
</html>
35 changes: 10 additions & 25 deletions src/main/resources/templates/error/500.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>500 View</title>
<title>500</title>

<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta name="description" content="This is error view" />
<meta name="description" content="This is 500 view" />
<meta name="author" content="Erwin Feng" />

<style>
* {
margin: 0;
padding: 0;
}
body {
background-color: #eee;
}
.home {
width: 300px;
height: 125px;
background-color: #333;
color: #eee;
text-align: center;
padding-top: 50px;
font-size: 50px;
border-radius: 5px;
margin: 100px auto 0;
}
</style>
<link rel="stylesheet" href="/css/error/style.css">
</head>
<body>
<div class="home">
<section class="home">
500
</div>
</section>

<footer class="footer">
Copyright &copy;2019
</footer>
</body>
</html>
Loading

0 comments on commit e1d870e

Please sign in to comment.