From abbc9ec443e84b43c512080f627019ace607d30b Mon Sep 17 00:00:00 2001 From: biezhi Date: Fri, 6 May 2022 13:39:45 +0800 Subject: [PATCH] release 2.1.1.RELEASE --- README.md | 39 ++++++++++++++++--- README_CN.md | 39 ++++++++++++++++--- blade-core/pom.xml | 2 +- .../com/hellokaton/blade/mvc/BladeConst.java | 2 +- blade-examples/pom.xml | 4 +- .../main/java/com/example/Application.java | 4 +- blade-kit/pom.xml | 2 +- blade-security/pom.xml | 2 +- blade-websocket/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 79 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f75aaba7..9b50757b 100644 --- a/README.md +++ b/README.md @@ -64,14 +64,14 @@ Run with `Maven`: com.hellokaton blade-core - 2.1.1.BETA + 2.1.1.RELEASE ``` or `Gradle`: ```sh -compile 'com.hellokaton:blade-core:2.1.1.BETA' +compile 'com.hellokaton:blade-core:2.1.1.RELEASE' ``` Write the `main` method and the `Hello World`: @@ -99,6 +99,7 @@ Open http://localhost:9000 in your browser to see your first `Blade` application - [**`Get Cookie`**](#get-cookie) - [**`Static Resource`**](#static-resource) - [**`Upload File`**](#upload-file) +- [**`Download File`**](#download-file) - [**`Set Session`**](#set-session) - [**`Render To Browser`**](#render-to-browser) - [**`Render Response`**](#render-json) @@ -397,8 +398,36 @@ public void upload(@Multipart FileItem fileItem){ } ``` +## Download File + +```java +@GET(value = "/download", responseType = ResponseType.STREAM) +public void download(Response response) throws IOException { + response.write("abcd.pdf", new File("146373013842336153820220427172437.pdf")); +} +``` + +**If you want to preview certain files in your browser** + +```java +@GET(value = "/preview", responseType = ResponseType.PREVIEW) +public void preview(Response response) throws IOException { + response.write(new File("146373013842336153820220427172437.pdf")); +} +``` + ## Set Session +The session is disabled by default, you must enable the session. + +```java +Blade.create() + .http(HttpOptions::enableSession) + .start(Application.class, args); +``` + +> 💡 It can also be enabled using a configuration file,`http.session.enabled=true` + ```java public void login(Session session){ // if login success @@ -554,7 +583,7 @@ The `hello.html` template ``` -[Render API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#render-com.ModelAndView-) +[Render API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#render-com.ModelAndView-) ## Redirects @@ -565,7 +594,7 @@ public void redirectToGithub(RouteContext ctx){ } ``` -[Redirect API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#redirect-java.lang.String-) +[Redirect API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#redirect-java.lang.String-) ## Write Cookie @@ -577,7 +606,7 @@ public void writeCookie(RouteContext ctx){ } ``` -[Cookie API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#cookie-java.lang.String-java.lang.String-) +[Cookie API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#cookie-java.lang.String-java.lang.String-) ## Web Hook diff --git a/README_CN.md b/README_CN.md index 4a94dcad..b52a1ad7 100644 --- a/README_CN.md +++ b/README_CN.md @@ -60,7 +60,7 @@ com.hellokaton blade-core - 2.1.1.BETA + 2.1.1.RELEASE ``` @@ -69,7 +69,7 @@ 或者 `Gradle`: ```sh -compile 'com.hellokaton:blade-core:2.1.1.BETA' +compile 'com.hellokaton:blade-core:2.1.1.RELEASE' ``` 编写 `main` 函数写一个 `Hello World`: @@ -98,6 +98,7 @@ public static void main(String[] args) { - [**`获取Cookie`**](#获取cookie) - [**`静态资源`**](#静态资源) - [**`上传文件`**](#上传文件) +- [**`下载文件`**](#下载文件) - [**`设置会话`**](#设置会话) - [**`渲染到浏览器`**](#渲染到浏览器) - [**`渲染JSON`**](#渲染json) @@ -396,8 +397,36 @@ public void upload(@Multipart FileItem fileItem){ } ``` +## 下载文件 + +```java +@GET(value = "/download", responseType = ResponseType.STREAM) +public void download(Response response) throws IOException { + response.write("abcd.pdf", new File("146373013842336153820220427172437.pdf")); +} +``` + +**如果你想在浏览器预览某些文件** + +```java +@GET(value = "/preview", responseType = ResponseType.PREVIEW) +public void preview(Response response) throws IOException { + response.write(new File("146373013842336153820220427172437.pdf")); +} +``` + ## 设置会话 +默认情况不开启会话功能,首先要开启会话 + +```java +Blade.create() + .http(HttpOptions::enableSession) + .start(Application.class, args); +``` + +> 💡 也可以使用配置文件开启,`http.session.enabled=true` + ```java public void login(Session session){ // if login success @@ -553,7 +582,7 @@ public static void main(String[] args) { ``` -[Render API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#render-com.ModelAndView-) +[Render API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#render-com.ModelAndView-) ## 重定向 @@ -564,7 +593,7 @@ public void redirectToGithub(RouteContext ctx){ } ``` -[Redirect API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#redirect-java.lang.String-) +[Redirect API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#redirect-java.lang.String-) ## 写入Cookie @@ -576,7 +605,7 @@ public void writeCookie(RouteContext ctx){ } ``` -[Cookie API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.BETA/com/hellokaton/blade/mvc/http/Response.html#cookie-java.lang.String-java.lang.String-) +[Cookie API](http://static.javadoc.io/com.hellokaton/blade-core/2.1.1.RELEASE/com/hellokaton/blade/mvc/http/Response.html#cookie-java.lang.String-java.lang.String-) ## 路由拦截 diff --git a/blade-core/pom.xml b/blade-core/pom.xml index f102bf7c..9541dfc9 100644 --- a/blade-core/pom.xml +++ b/blade-core/pom.xml @@ -5,7 +5,7 @@ com.hellokaton blade - 2.1.1.BETA + 2.1.1.RELEASE 4.0.0 diff --git a/blade-core/src/main/java/com/hellokaton/blade/mvc/BladeConst.java b/blade-core/src/main/java/com/hellokaton/blade/mvc/BladeConst.java index 2783294a..2a2b7229 100644 --- a/blade-core/src/main/java/com/hellokaton/blade/mvc/BladeConst.java +++ b/blade-core/src/main/java/com/hellokaton/blade/mvc/BladeConst.java @@ -31,7 +31,7 @@ public interface BladeConst { int DEFAULT_SERVER_PORT = 9000; String DEFAULT_SERVER_ADDRESS = "0.0.0.0"; String LOCAL_IP_ADDRESS = "127.0.0.1"; - String VERSION = "2.1.1.BETA"; + String VERSION = "2.1.1.RELEASE"; String WEB_JARS = "/webjars/"; String CLASSPATH = BladeKit.getCurrentClassPath(); String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; diff --git a/blade-examples/pom.xml b/blade-examples/pom.xml index 75515898..e17e0d92 100644 --- a/blade-examples/pom.xml +++ b/blade-examples/pom.xml @@ -5,7 +5,7 @@ com.hellokaton blade - 2.1.1.BETA + 2.1.1.RELEASE 4.0.0 @@ -23,7 +23,7 @@ com.hellokaton blade-security - 2.1.1.BETA + 2.1.1.RELEASE org.projectlombok diff --git a/blade-examples/src/main/java/com/example/Application.java b/blade-examples/src/main/java/com/example/Application.java index 4491be5a..d1112a1f 100644 --- a/blade-examples/src/main/java/com/example/Application.java +++ b/blade-examples/src/main/java/com/example/Application.java @@ -14,6 +14,7 @@ import com.hellokaton.blade.mvc.multipart.FileItem; import com.hellokaton.blade.mvc.ui.ResponseType; import com.hellokaton.blade.options.CorsOptions; +import com.hellokaton.blade.options.HttpOptions; import com.hellokaton.blade.security.csrf.CsrfMiddleware; import com.hellokaton.blade.security.limit.LimitMiddleware; import com.hellokaton.blade.security.limit.LimitOptions; @@ -81,7 +82,7 @@ public String verifyToken(Request req) { } @GET(value = "/preview/:id", responseType = ResponseType.PREVIEW) - public void preview(@PathParam String id, Response response) throws Exception { + public void preview(@PathParam String id, Response response) throws IOException { response.write(new File("/Users/biezhi/Downloads/146373013842336153820220427172437.pdf")); } @@ -98,6 +99,7 @@ public static void main(String[] args) { Blade.create() .cors(corsOptions) + .http(HttpOptions::enableSession) // .use(new CsrfMiddleware()) // .use(new LimitMiddleware(limitOptions)) .listen().start(Application.class); diff --git a/blade-kit/pom.xml b/blade-kit/pom.xml index e037d262..2eb5d3bf 100644 --- a/blade-kit/pom.xml +++ b/blade-kit/pom.xml @@ -5,7 +5,7 @@ com.hellokaton blade - 2.1.1.BETA + 2.1.1.RELEASE 4.0.0 diff --git a/blade-security/pom.xml b/blade-security/pom.xml index 715cc37f..7fc31a07 100644 --- a/blade-security/pom.xml +++ b/blade-security/pom.xml @@ -5,7 +5,7 @@ blade com.hellokaton - 2.1.1.BETA + 2.1.1.RELEASE 4.0.0 diff --git a/blade-websocket/pom.xml b/blade-websocket/pom.xml index d49f1daf..a8691459 100644 --- a/blade-websocket/pom.xml +++ b/blade-websocket/pom.xml @@ -5,7 +5,7 @@ com.hellokaton blade - 2.1.1.BETA + 2.1.1.RELEASE 4.0.0 diff --git a/pom.xml b/pom.xml index b181887e..af2b42ae 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.hellokaton blade - 2.1.1.BETA + 2.1.1.RELEASE pom blade