Skip to content

Commit 7d84917

Browse files
committed
add wiki
1 parent 1d06016 commit 7d84917

File tree

6 files changed

+707
-1
lines changed

6 files changed

+707
-1
lines changed

docs/wiki/home.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[![Maven Central](https://img.shields.io/maven-central/v/com.codingapi.springboot/springboot-starter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.codingapi.springboot%22%20AND%20a:%22springboot-starter%22)
2+
3+
Welcome to the springboot-framework !
4+
5+
maven install
6+
```
7+
<!-- Springboot领域驱动框架 -->
8+
<dependency>
9+
<groupId>com.codingapi.springboot</groupId>
10+
<artifactId>springboot-starter</artifactId>
11+
<version>${last.version}</version>
12+
</dependency>
13+
14+
<!-- 快速数据呈现框架 -->
15+
<dependency>
16+
<groupId>com.codingapi.springboot</groupId>
17+
<artifactId>springboot-starter-data-fast</artifactId>
18+
<version>${last.version}</version>
19+
</dependency>
20+
21+
<!-- Id自增策略框架 -->
22+
<dependency>
23+
<groupId>com.codingapi.springboot</groupId>
24+
<artifactId>springboot-starter-id-generator</artifactId>
25+
<version>${last.version}</version>
26+
</dependency>
27+
28+
<!-- security&jwt权限框架 -->
29+
<dependency>
30+
<groupId>com.codingapi.springboot</groupId>
31+
<artifactId>springboot-starter-security-jwt</artifactId>
32+
<version>${last.version}</version>
33+
</dependency>
34+
```
35+
36+
37+
[springboot-starter](./springboot-starter)
38+
[springboot-starter-security-jwt](./springboot-starter-security-jwt)
39+
[springboot-starter-id-generator](./springboot-starter-id-generator)
40+
[springboot-starter-data-fast](./springboot-starter-data-fast.md)
41+
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
springboot-starter-data-fast
2+
3+
基于JPA的快速API能力服务
4+
5+
```java
6+
package com.codingapi.springboot.example.query;
7+
8+
import com.codingapi.springboot.example.infrastructure.jpa.entity.DemoEntity;
9+
import com.codingapi.springboot.example.infrastructure.jpa.pojo.PageSearch;
10+
import com.codingapi.springboot.fast.annotation.FastController;
11+
import com.codingapi.springboot.fast.annotation.FastMapping;
12+
import com.codingapi.springboot.framework.dto.response.MultiResponse;
13+
import org.springframework.security.access.prepost.PreAuthorize;
14+
import org.springframework.web.bind.annotation.RequestMethod;
15+
16+
@FastController
17+
public interface FastDemoApi {
18+
19+
20+
@PreAuthorize(value = "hasRole('ROLE_ADMIN')")
21+
@FastMapping(
22+
method = RequestMethod.GET,
23+
mapping = "/api/demo/findByName1",
24+
value = "select d from DemoEntity d where name = :name",
25+
countQuery = "select count(d) from DemoEntity d where name = :name")
26+
MultiResponse<DemoEntity> findByName1(PageSearch query);
27+
28+
29+
30+
@PreAuthorize(value = "hasRole('ROLE_USER')")
31+
@FastMapping(
32+
method = RequestMethod.GET,
33+
mapping = "/api/demo/findByName2",
34+
value = "select d from DemoEntity d where name = :name",
35+
countQuery = "select count(d) from DemoEntity d where name = :name")
36+
MultiResponse<DemoEntity> findByName2(PageSearch query);
37+
38+
}
39+
40+
```
41+
@FastController 用于标记当前接口为Fast接口
42+
@FastMapping 用于标记当前接口的映射关系
43+
mapping为接口映射路径,method为接口请求方法
44+
value为查询语句,countQuery为查询总数语句,query为查询参数,支持分页查询,排序查询,查询参数等等
45+
MultiResponse为返回结果
46+
@PreAuthorize(value = "hasRole('ROLE_USER')") 用于标记当前接口的权限,如果不需要权限可以不用添加
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
springboot-starter-id-generator
2+
3+
一个单服务下的id自增构造器,为了解决id由数据库生成的问题,如果是分布式服务,可以使用snowflake算法生成id,如果是单服务,可以使用这个构造器生成id
4+
5+
```java
6+
7+
import com.codingapi.springboot.generator.IdGenerate;
8+
import lombok.Getter;
9+
10+
/**
11+
* @author lorne
12+
* @since 1.0.0
13+
*/
14+
public class Demo implements IdGenerate {
15+
16+
@Getter
17+
private Integer id;
18+
19+
@Getter
20+
private String name;
21+
22+
public Demo(String name) {
23+
this.id = generateIntId();
24+
this.name = name;
25+
}
26+
27+
}
28+
29+
```
30+
31+
只需要实现IdGenerate接口即可,然后调用generateIntId()方法即可生成id。
32+
33+
IdGenerate接口提供了两个方法,generateIntId()和generateLongId(),分别用于生成int类型和long类型的id。
34+
也可以使用generateStringId()方法生成String类型的id。
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
springboot-starter-security-jwt 功能介绍
2+
3+
配置文件,默认参数即说明
4+
```properties
5+
# JWT密钥 需大于32位的字符串
6+
codingapi.security.jwt-secret=codingapi.security.jwt.secretkey
7+
# JWT AES密钥
8+
codingapi.security.ase-key=QUNEWCQlXiYqJCNYQ1phc0FDRFgkJV4mKiQjWENaYXM=
9+
# JWT AES IV
10+
codingapi.security.aes-iv=QUNYRkdIQEVEUyNYQ1phcw==
11+
12+
# JWT 有效时间(毫秒) 15分钟有效期 1000*60*15=900000
13+
codingapi.security.jwt-time=900000
14+
# JWT 更换令牌时间(毫秒) 10分钟后更换令牌 1000*60*10=600000
15+
codingapi.security.jwt-rest-time=600000
16+
17+
# Security 配置 请求权限拦截地址
18+
codingapi.security.authenticated-urls=/api/**
19+
# Security 配置 登录地址
20+
codingapi.security.login-processing-url=/user/login
21+
# Security 配置 登出地址
22+
codingapi.security.logout-url=/user/logout
23+
# Security 配置 不拦截的地址
24+
codingapi.security.ignore-urls=/open/**
25+
# 禁用CSRF
26+
codingapi.security.disable-csrf=true
27+
# 禁用CORS
28+
codingapi.security.disable-cors=true
29+
```
30+
31+
## 默认账户密码
32+
security默认的账户密码为admin/admin,可以通过重写UserDetailsService来实现自定义账户密码
33+
```java
34+
@Bean
35+
public UserDetailsService userDetailsService(PasswordEncoder passwordEncoder) {
36+
String password = passwordEncoder.encode("12345678");
37+
38+
UserDetails admin = User.withUsername("admin")
39+
.password(password)
40+
.roles("ADMIN")
41+
.build();
42+
43+
UserDetails user = User.withUsername("user")
44+
.password(password)
45+
.roles("USER")
46+
.build();
47+
48+
return new InMemoryUserDetailsManager(admin, user);
49+
}
50+
```
51+
也可以通过数据库账户获取账户数据,请自己实现UserDetailsService接口
52+
53+
## 登录拦截
54+
可以通过重写SecurityLoginHandler来实现自定义登录拦截
55+
```java
56+
@Bean
57+
public SecurityLoginHandler securityLoginHandler(){
58+
return (request, response, handler) -> {
59+
//TODO 自定义登录拦截
60+
};
61+
}
62+
```
63+
64+
## 获取当前用户
65+
66+
通过TokenContext获取当前用户信息
67+
```java
68+
@GetMapping("/user")
69+
public String user(){
70+
return TokenContext.current().getUsername();
71+
}
72+
```
73+
74+
可以通过Token的extra字段来存储用户的更多信息,然后通过TokenContext获取
75+
```java
76+
@GetMapping("/user")
77+
public String user(){
78+
return TokenContext.current().getExtra("user");
79+
}
80+
```

0 commit comments

Comments
 (0)