# AndServer **Repository Path**: hihopeorg/AndServer ## Basic Information - **Project Name**: AndServer - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 2 - **Created**: 2021-02-27 - **Last Updated**: 2024-10-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AndServer **本项目是基于开源项目AndServer进行ohos化的移植和开发的,可以通过项目标签以及github地址( https://github.com/yanzhenjie/AndServer )追踪到原项目版本** #### 项目介绍 - 项目名称:AndServer - 所属系列:ohos的第三方组件适配移植 - 功能:动态Http API,就像Java的Servlet一样写接口;部署静态网站,例如纯Html,支持JS、CSS、Image分离;部署动态网站,例如Html表单,当然可以结合上面的第一点Http接口。 - 项目移植状态:完成 - 调用差异:无差异。 - 项目作者和维护人:hihope - 联系方式:hihope@hoperun.com - 原项目Doc地址:https://github.com/yanzhenjie/AndServer - 基线release版本:V2.1.6,SHA1:f6e16df4aedf3165e073607d80ab8e000cf4f965 - 编程语言:Java - 外部库依赖: 1.com.yanzhenjie.apache:fileupload:1.4 2.com.yanzhenjie.apache:httpcore:4.4.13.2 #### 展示效果 ![avatar](screenshot/preview.gif) #### 安装教程 1. 下载服务库har包AndServer_ohos.har。 2. 启动 DevEco Studio,将下载的har包,导入工程目录“entry->libs”下。 3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。 ``` dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) …… } ``` 4. 在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。 5. 添加 plugin 到你的项目 build script ```gradle buildscript { repositories { jcenter() mavenCentral() google() } dependencies { classpath 'com.yanzhenjie.andserver:plugin:2.1.7' ... } } ... ``` 6. 添加gradle自定义插件到你的 module: ```gradle apply plugin: 'com.yanzhenjie.andserver' ... dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.7' ... } ``` #### 使用说明: ```java Server server = AndServer.webServer(context) .port(8080) .timeout(10, TimeUnit.SECONDS) .build(); // 开启服务. server.startup(); ... // 关闭服务 server.shutdown(); ``` http 动态接口的示例如下: ```java @RestController @RequestMapping(path = "/user") public class UserController { @PostMapping("/login") public String login(@RequestParam("account") String account, @RequestParam("password") String password) { ... return "Successful."; } @GetMapping(path = "/{userId}") public User info(@PathVariable("userId") String userId, @QueryParam("fields") String fields) { User user = findUserById(userId, fields); ... return user; } @PutMapping(path = "/{userId}") public void modify(@PathVariable("userId") String userId @RequestParam("age") int age) { ... } } ``` 上面的代码将生成以下三个http api: ```text POST http://.../user/login GET http://.../user/uid_001?fields=id,name,age PUT http://.../user/uid_001 ``` #### 版本迭代 - v1.0.1 #### 版权和许可信息 Apache license 2.0