Skip to content

Commit

Permalink
release 2.1.1.RELEASE
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed May 6, 2022
1 parent 5fd0dc0 commit abbc9ec
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 19 deletions.
39 changes: 34 additions & 5 deletions README.md
Expand Up @@ -64,14 +64,14 @@ Run with `Maven`:
<dependency>
<groupId>com.hellokaton</groupId>
<artifactId>blade-core</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</dependency>
```

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`:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -554,7 +583,7 @@ The `hello.html` template
</html>
```

[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

Expand All @@ -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

Expand All @@ -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

Expand Down
39 changes: 34 additions & 5 deletions README_CN.md
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.hellokaton</groupId>
<artifactId>blade-core</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</dependency>
```

Expand All @@ -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`
Expand Down Expand Up @@ -98,6 +98,7 @@ public static void main(String[] args) {
- [**`获取Cookie`**](#获取cookie)
- [**`静态资源`**](#静态资源)
- [**`上传文件`**](#上传文件)
- [**`下载文件`**](#下载文件)
- [**`设置会话`**](#设置会话)
- [**`渲染到浏览器`**](#渲染到浏览器)
- [**`渲染JSON`**](#渲染json)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -553,7 +582,7 @@ public static void main(String[] args) {
</html>
```

[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-)

## 重定向

Expand All @@ -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

Expand All @@ -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-)

## 路由拦截

Expand Down
2 changes: 1 addition & 1 deletion blade-core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hellokaton</groupId>
<artifactId>blade</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions blade-examples/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hellokaton</groupId>
<artifactId>blade</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>com.hellokaton</groupId>
<artifactId>blade-security</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
4 changes: 3 additions & 1 deletion blade-examples/src/main/java/com/example/Application.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion blade-kit/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hellokaton</groupId>
<artifactId>blade</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion blade-security/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>blade</artifactId>
<groupId>com.hellokaton</groupId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion blade-websocket/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.hellokaton</groupId>
<artifactId>blade</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -5,7 +5,7 @@

<groupId>com.hellokaton</groupId>
<artifactId>blade</artifactId>
<version>2.1.1.BETA</version>
<version>2.1.1.RELEASE</version>
<packaging>pom</packaging>

<name>blade</name>
Expand Down

0 comments on commit abbc9ec

Please sign in to comment.