doc
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# 配置说明
|
# 配置说明
|
||||||
# application.xml 配置:
|
## application.xml 配置:
|
||||||
```xml
|
```xml
|
||||||
<!--
|
<!--
|
||||||
文件说明:
|
文件说明:
|
||||||
@@ -366,7 +366,7 @@
|
|||||||
</application>
|
</application>
|
||||||
```
|
```
|
||||||
|
|
||||||
# source.properties 配置:
|
## source.properties 配置:
|
||||||
```properties
|
```properties
|
||||||
|
|
||||||
# CacheSource @Resource(name="usersession")
|
# CacheSource @Resource(name="usersession")
|
||||||
@@ -420,7 +420,7 @@ redkale.datasource.platf.write.user = root
|
|||||||
redkale.datasource.platf.write.password = 12345678
|
redkale.datasource.platf.write.password = 12345678
|
||||||
```
|
```
|
||||||
|
|
||||||
# logging.properties 配置:
|
## logging.properties 配置:
|
||||||
```properties
|
```properties
|
||||||
|
|
||||||
handlers = java.util.logging.ConsoleHandler,java.util.logging.FileHandler
|
handlers = java.util.logging.ConsoleHandler,java.util.logging.FileHandler
|
||||||
|
|||||||
@@ -6,3 +6,59 @@
|
|||||||
     3、Service类被标记```@Component``` <br>
|
     3、Service类被标记```@Component``` <br>
|
||||||
|
|
||||||
  Redkale进程启动时扫描可加载的Service实现类,根据配置文件配置的模式采用```ASM```技术动态生成相应的Service临时类进行实例化,并注册到ResourceFactory同其他Service、Servlet依赖注入。
|
  Redkale进程启动时扫描可加载的Service实现类,根据配置文件配置的模式采用```ASM```技术动态生成相应的Service临时类进行实例化,并注册到ResourceFactory同其他Service、Servlet依赖注入。
|
||||||
|
|
||||||
|
## Service使用类型
|
||||||
|
|类型|使用注解|场景说明|
|
||||||
|
| --- | --- | --- |
|
||||||
|
|默认加载|```@AutoLoad```或无注解|默认的Service会自动加载并初始化,且会自动生成对应协议层Servlet|
|
||||||
|
|依赖加载|```@AutoLoad(false)```|此类Service只有被其他服务依赖或者显式的配置时才会被初始化,主要用于工具类功能服务, 比如```DataSource```、```CacheSource```|
|
||||||
|
|本地模式|```@Local```|此类Service无论配不配成远程模式,都不会转成远程模式,主要用于功能依赖本地环境或者参数无法序列化的服务|
|
||||||
|
|组件模式|```@Component```|此类Service不会被动态生成协议层Servlet,主要用于无需提供对进程外提供接口的服务, 比如```DataSource```、```CacheSource```的实现|
|
||||||
|
# 基本用法
|
||||||
|
```java
|
||||||
|
@RestService(comment = "用户服务模块")
|
||||||
|
public class UserService implements Service {
|
||||||
|
|
||||||
|
@Resource(name = "platf")
|
||||||
|
private DataSource source;
|
||||||
|
|
||||||
|
@RestMapping(auth = true, comment = "更改密码")
|
||||||
|
public RetResult<String> updatePwd(@RestUserid long userid, UserPwdBean bean) {
|
||||||
|
//逻辑处理
|
||||||
|
return RetResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestMapping(auth = true, comment = "更新用户介绍")
|
||||||
|
public RetResult<String> updateIntro(@RestUserid long userid, String intro) {
|
||||||
|
intro = Utility.orElse(intro, ""); //为null则用""
|
||||||
|
//更新数据库
|
||||||
|
source.updateColumn(UserDetail.class, userid, UserDetail::getIntro, intro);
|
||||||
|
return RetResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestMapping(auth = true, comment = "修改用户性别(异步方法)")
|
||||||
|
public CompletableFuture<RetResult<String>> updateGender(@RestUserid long userid, short gender) {
|
||||||
|
if (gender != GENDER_MALE && gender != GENDER_FEMALE) {
|
||||||
|
return RetCodes.retResultFuture(RET_USER_GENDER_ILLEGAL);
|
||||||
|
}
|
||||||
|
//更新数据库
|
||||||
|
return source.updateColumnAsync(UserDetail.class, userid, UserDetail::getGender, gender)
|
||||||
|
.thenApply(v -> RetResult.success());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
  ```@RestUserid int userid```为当前用户Id, 值是在BaseServlet里进行设置,userid可以是String、long、int类型。
|
||||||
|
|
||||||
|
## 远程模式Service
|
||||||
|
  远程Servie其实是提供RPC接口,需要配置文件中显式配置才可使用远程模式。
|
||||||
|
```xml
|
||||||
|
<group name="remote-A">
|
||||||
|
<node addr="192.168.10.111" port="7070"/>
|
||||||
|
<node addr="192.168.10.112" port="7070"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
|
<server protocol="HTTP" host="0.0.0.0" port="8080">
|
||||||
|
<services autoload="true" group="remote-A"/>
|
||||||
|
<service name="" value="org.redkale.demo.user.UserService" group="remote-A"/>
|
||||||
|
</server>
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user