Open zero code programming?

Posted by jannoy on Thu, 03 Mar 2022 12:03:23 +0100

APIJSAON (I: Introduction)

background

Due to various wonderful abbreviations, chaotic naming, outdated documents, out of sync with interfaces, unstable or arbitrary changes of data types, hundreds or even thousands of chaotic status codes, all kinds of wrangling between the front end and the back end, cumbersome whole development process, long development cycle and other reasons in the development process of traditional development, the emergence of APIJSON came into being.

1, What is APIJSAON?

First, look at the name APIJSON. API means that this project belongs to the project of interface development. JSON means that the transmission data format is JSON format. In other words, if this project is used as the back-end support, there is no need to write interfaces such as addition, deletion, modification and query for each table. It only needs to create tables in the data connected to this project and configure interface permissions. There is no need for too much development. Even if you want to change the structure, you only need to modify the table fields. Think about just deploying a back-end project. Now the interfaces needed are basically written and called directly.

2, Installation steps

1. Environment configuration

DK: 1.8+

MAVEN: 3.5+

Mysql: 5.7

JetBrains IntelliJ IDEA 2019.2

2. Download items

Download using git clone:

git clone https://github.com/APIJSON/APIJSON-Demo.git

Or APIJSON project address( https://github.com/APIJSON/AP... )Download

3. Import project

Idea or Eclipse import:

Top menu file > Import > Maven > existing Maven projects > next > Browse

Select the project directory / apijson demo master / apijson Java Server / apijsonboot

Download dependency. When dependency error is reported, add the jar package in libs in the same directory to Build Path

4. Error resolution

Possible POM XML will report errors, for example:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

This sentence in this code prompts an error:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

There are also possible errors:

Add a dependent version.

Modification steps:

  • Please modify the Maven image address in Eclipse to download or update faster. The specific method is Baidu;
  • Open eclipse - > windows - > Preferences - > Maven - > installations - > Add. This button is used to specify
    maven's installation directory is not recommended. It needs to be set by yourself.
  • Open eclipse - > windows - > Preferences - > Maven - > user settings, which specifies setting xml
    At the same time, it leads to its own local maven warehouse.

3, Database

1. Configuration

You need to change the link corresponding to your own database in DemoSQLConfig, lines 40-61

2. Import

Import the SQL script under apijson demo / MySQL:

4, New interface

1. Add data in the background

CREATE TABLE `b_stone` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `cost` int(10) NULL COMMENT 'cost',
  `price` int(10) NULL COMMENT 'Selling price',
  `length` int(10) NULL,
  `width`  int(10) NULL,
  `height` int(10) NULL,
  `weight` float(8,1) NULL,
  `creationdate` datetime default CURRENT_TIMESTAMP COMMENT 'Creation time',
  `modifydate` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Modification time',
  `modifier` varchar(80) NULL,
  PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. Add objects and configure permissions in the Model

Add a new class in the model directory of the project

package apijson.demo.server.model;

import zuo.biao.apijson.MethodAccess;

@MethodAccess
public class Stone {
}

Annotate the configuration of @ MethodAccess. You can refer to other classes

Because our class name and database table name are inconsistent, we need to register. If it's the same, you don't need it.

Set the actual table name of the database DemoSQLConfig, 38 rows

//Table name mapping can hide the real table name. This can be done for tables with high security requirements
    static {
        TABLE_KEY_MAP.put(User.class.getSimpleName(), "apijson_user");
        TABLE_KEY_MAP.put(Privacy.class.getSimpleName(), "apijson_privacy");
        TABLE_KEY_MAP.put(Stone.class.getSimpleName(), "b_stone"); // < -- this sentence
    }

Registration permission is necessary so that the program can use the class permission you configured to manage your interface

DemoSQLConfig, line 48

static { //Registration authority
        ACCESS_MAP.put(User.class.getSimpleName(), getAccessMap(User.class.getAnnotation(MethodAccess.class)));
....
        ACCESS_MAP.put(Stone.class.getSimpleName(), getAccessMap(Stone.class.getAnnotation(MethodAccess.class)));
    }

3. Request parameter verification request table configuration

You can set the structure field to configure the JSON parameters of the automatic verification request:

"VERIFY":{
  "type{}":[0,1,2]
}

You can check whether the value of type is one of 0, 1 and 2.
also

"VERIFY": { "money&{}":">0,<=10000" }              //Automatically verify whether money > 0 & money < = 10000
"TYPE": { "balance": "Double" }                    //Automatically verify whether the balance type is Double
"UNIQUE": "phone"                                  //Force the value of phone to be one that does not exist in the database
"NECESSARY": "id,name"                             //Forced transfer of ID and name fields
"DISALLOW": "balance"                              //Prohibit transferring balance field
"INSERT": { "@role": "OWNER" }                     //If @ role is not transferred, it will be added automatically
"UPDATE": { "id@": "User/id" }                     //Force key value pairs

See for all operators Operation.java (opens new window)

4. Start the project

5. Request interface test


So far, an open zero code programming project has been successfully run.

Topics: Java MySQL Spring Spring Boot Programmer