Backend mounting: Write 8 interfaces in three lines of code !, Backend 3 rows
Some may think:
How is this possible?
Even with SpringBoot with almost zero configuration, three lines of code are required to write the simplest interface!
@RequestMapping("test/{request}") public String test(@PathVariable String request) { return request + ": Hello World"; }
There will be 24 lines of code for eight useless Hello World interfaces!
This is not countedJoin SQL with JDBCOrCall the ORM LibraryCode!
Not to mention writingXML configurationOther libraries!
That's right. It's just like this in the traditional way.
Get a user:
base_url/get/user
Get a user list:
base_url/get/user/list
Get a comment:
base_url/get/comment
Get a comment list:
base_url/get/comment/list
...
Only query. A table (corresponding to the client model) requires two interfaces,
If you add, delete, modify, batch delete, and statistics, you have to have eight interfaces!
So how can I solve it?
Requests of the same type only use one interface:
Add base_url/post
Delete (including Batch) base_url/delete
Modify (including Batch) base_url/put
Query (including list) base_url/get
Base_url/head statistics
Use the most common query request example:
Get a user:
base_url/get/
Get a user list:
base_url/get/
Get a comment:
base_url/get
Get a comment list:
base_url/get
...
All use the same interface!
We use APIJSON to operate a table, such as the User table. It is enough to write three lines of code:
// Add permissions to the Registry and use the default configuration @ MethodAccesspublic class User {// The content is generally only used for table field description and Android App development. The server does not need to write anything .} // Add the access accessMap. put (User. class. getSimpleName (), getAccessMap (User. class. getAnnotation (MethodAccess. class) in Verifier )));
Alternatively, you can customize the role permissions of the POST request:
@ MethodAccess (
POST = {UNKNOWN, ADMIN} // only allow non-Logon and administrator roles to add new users. The default configuration is {LOGIN, ADMIN}
) Public class User {}
Then you can run the Server project to request:
URL: http: // 39.108.143.172: 8080/get
Form:
{ "User": { "id": 82001 }}
Return Value:
{ "User": { "id": 82001, "sex": 0, "name": "Test", "tag": "APIJSON User", "head": "http://static.oschina.net/uploads/user/19/39085_50.jpg", "contactIdList": [ 82004, 82021, 70793 ], "pictureList": [ "http://common.cnblogs.com/images/icon_weibo_24.png" ], "date": "2017-02-01 19:21:50.0" }, "code": 200, "msg": "success"}
The above is just a User. If we want to check the list of female users, we can do this:
URL: http: // 39.108.143.172: 8080/get
Form:
{"[]": {// Array "User": {"sex": 1, // Gender: female "@ column": "id, name "// only the id and name fields are required }}}
Return Value:
{ "[]": [ { "User": { "id": 82002, "name": "Happy~" } }, { "User": { "id": 82003, "name": "Wechat" } }, { "User": { "id": 82005, "name": "Jan" } } ], "code": 200, "msg": "success"}
Is the User encapsulated by another layer? Name the array User [] to remove it:
Form:
{"User []": {// extract User "User": {"sex": 1, // Gender: female "@ column": "id, name "// only the id and name fields are required }}}
Return Value:
{ "User[]": [ { "id": 82002, "name": "Happy~" }, { "id": 82003, "name": "Wechat" }, { "id": 82005, "name": "Jan" } ], "code": 200, "msg": "success"}
Do you need to further extract the name? User-name [] meets your requirements:
Form:
{"User-name []": {// extract User. name "User": {"sex": 1, // The Gender is female "@ column": "name" // only the name field is required }}}
Return Value:
{ "User-name[]": [ "Happy~", "Wechat", "Jan", "Meria", "Tommy" ], "code": 200, "msg": "success"}
HoweverJoin multiple tablesDo not remove the array:
Form:
{"[]": {"Comment" :{}, // Comment "User": {// the User who posted the Comment "id @": "/Comment/userId" // User. id = Comment. userId }}}
Return Value:
{ "[]": [ { "Comment": { "id": 3, "toId": 0, "userId": 82002, "momentId": 15, "date": "2017-02-01 19:20:50.0", "content": "This is a Content...-3" }, "User": { "id": 82002, "sex": 1, "name": "Happy~", "tag": "iOS", "head": "http://static.oschina.net/uploads/user/1174/2348263_50.png?t=1439773471000", "contactIdList": [ 82005, 82001, 38710 ], "pictureList": [], "date": "2017-02-01 19:21:50.0" } }, { "Comment": { "id": 4, "toId": 0, "userId": 38710, "momentId": 470, "date": "2017-02-01 19:20:50.0", "content": "This is a Content...-4" }, "User": { "id": 38710, "sex": 0, "name": "TommyLemon", "tag": "Android&Java", "head": "http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "contactIdList": [ 82003, 82005 ], "pictureList": [ "http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png" ], "date": "2017-02-01 19:21:50.0" } } ], "code": 200, "msg": "success"}
There is also a dynamic Moment and Its like user list:
{"Moment" :{}, "User []": {"User": {"id {}@": "Moment/praiseUserIdList" // id is in the thumb list praiseUserIdList }}}
Similar to the personal data interface:
{"User" :{}, "Moment []": {// "Moment ":{
"@ Order": "date-", // sort by release date in reverse order "userId @": "User/id "}}}
Dynamic list similar to circle of friends:
{"[]": {"Count": 3, // only 3 "pages": 2, // The "Moment ":{}, "User": {"id @": "/Moment/userId"}, "Comment []": {"Comment": {"momentId @": "[]/Moment/id "}}}}
...
Any structure, any content, any combination,
You can customize the JSON structure, field content, and table join query!
"Key []": {} // query array "key {}": [, 3] // The range of matching options is "key {}": "<= 10, length (key)> 1... "// matching condition range" key () ":" function (Type0: value0, Type1: value1 ...) "// Remote Call function" key @ ":" key0/key1... /targetKey "// reference value assignment" key $ ":" SQL search expression "// fuzzy search" key? ":" Regular Expression "// Regular Expression matching" key + ": Object of the specified type of key // Add/extend" key -": key: specify the type of Object // delete/remove "name: alias" // create an alias "@ column": "id, sex, name" // return field "@ group ": "userId" // grouping method "@ having": "max (id)> = 100" // aggregate function "@ order": "date -, name + "// sorting method
All of the above are query requests. Try addition, deletion, modification, and statistics again:
Add: http: // 39.108.143.172: 8080/post
{"Comment": {"userId": 82001, "momentId": 15, "content": "test new Comment"}, "tag": "Comment "}
Delete: http: // 39.108.143.172: 8080/delete
{ "Comment": { "id": 1510394480987 }, "tag": "Comment"}
Change: http: // 39.108.143.172: 8080/put
{"Comment": {"id": 22, "content": "Test modify Comment"}, "tag": "Comment "}
Batch delete: http: // 39.108.143.172: 8080/delete
{ "Comment": { "id{}": [1510394480987, 1510394804925] }, "tag": "Comment[]"}
Batch modification: http: // 39.108.143.172: 8080/put
{"Comment": {"id {}": [22,114], "content": "Test batch modify comments"}, "tag": "Comment []"}
Statistics: http: // 39.108.143.172: 8080/head
{"Comment": {"content $": "% test %" // The content contains two words for the test }}
Recall,CodeAfter three rows are written, eight interfaces including addition, deletion, modification, and query operations and so on are implemented!
In fact, you don't need to write the interface yourself when using APIJSON! These three lines of code are actually used for permission management!
Websites such as personal blogs and non-commercial news websites do not have permission to control such websites,
Change the global configuration without permission verification, so you don't need to write a line of code!!!
APIJSON-backend super-light speed development framework
GithubSource code and documentation (click in the upper-right cornerStar supports ^_^)
Https://github.com/TommyLemon/APIJSON
Download the client (test server address:Http: // 39.108.143.172: 8080)
APIJSONClientApp.apk