# declex **Repository Path**: chinasoft5_ohos/declex ## Basic Information - **Project Name**: declex - **Description**: 一款能快速开发Ohos的注解使用工具。让你专注于真正重要的事情,通过简化代码,可以简化代码的维护 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-17 - **Last Updated**: 2024-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # declex #### 项目介绍 - 项目名称:declex - 所属系列:openharmony的第三方组件适配移植 - 功能:declex是一个强大的框架,它减少了Java语言的冗长,增强了依赖/视图注入,从而允许以创纪录的速度创建Ohos应用程序,它完全基于ohosannotation。 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 Beta1 - 基线版本:Release 2.0.a.24 #### 效果演示 ![screenshot](screenshot/declex.gif) #### 安装教程 1.在项目根目录下的build.gradle文件中, ```groovy // 添加maven仓库 repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } ``` 2.在entry模块的build.gradle文件中, ```groovy // 添加依赖库 dependencies { annotationProcessor "com.gitee.chinasoft_ohos:declex:1.0.0" implementation(project(":declex_actions")) implementation 'com.gitee.chinasoft_ohos:declex-api:1.0.0' implementation 'com.gitee.chinasoft_ohos:activeohos-declex:0.0.1-SNAPSHOT' implementation 'com.gitee.chinasoft_ohos:saripaar-declex:0.0.1-SNAPSHOT' } ``` 在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 ```java @EAbility(ResourceTable.Layout_ability_demo) public class DemoAbility extends Ability { /* 查询列表@Model(query = "Id > 0") List users;*/ @Model(query = "Id = 1") User_ user;//注入被@UseModel的model @ComponentById(ResourceTable.Id_tv_name) Text tvName; @ComponentById(ResourceTable.Id_tv_age) Text tvAge; @ComponentById(ResourceTable.Id_tv_email) Text tvEmail; @ComponentById(ResourceTable.Id_tv_description) TextField tvDescription; @AfterInject void afterInject() {//user被注入之后回调 user.setName("Alice"); user.setEmail("alice@example.com"); user.setAge(22); } @AfterViews void afterView() { if (user != null) { tvName.setText(String.format("name:%s", user.getName())); tvAge.setText(String.format("age:%s", user.getAge())); tvEmail.setText(String.format("email:%s", user.getEmail())); tvDescription.setText(user.getDescription()); } } @Click void save() { user.setDescription(tvDescription.getText().toString()); user.save(); $Toast("save succeed"); } @Click void event() { //UserEventBean_.post(); UserEventBean_.create().setName(user.getName()).postEvent(); } @Click void server_model() { $ServerModelAbility(); } @Event void onUserEventBean(String name) {//接收事件,生成userEventBean事件类,成员变量name $Toast("name=" + name); } @Click void populate_view() { $PopulateViewsAbility().withResult(100); } @Override protected void onAbilityResult(int requestCode, int resultCode, Intent data) { super.onAbilityResult(requestCode, resultCode, data); if (requestCode == 100) { User_ user = new Select().from(User_.class).where("Id=?", 1).executeSingle(); if (user != null) { tvDescription.setText(user.getDescription()); } } } } ``` 本项目主要依赖以下库 * [ohosannotation](https://gitee.com/chinasoft5_ohos/ohosannotations) :branch = declex * [Activeohos](https://gitee.com/chinasoft5_ohos/Activeohos) :branch = declex * [saripaar](https://gitee.com/chinasoft5_ohos/saripaar) :branch = declex #### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 #### 版本迭代 - 1.0.0 #### 版权和许可信息 [Apache License, Version 2.0](LICENSE)