Rocket-API
WEB development framework. Rocket-api provides a solution to traditional business requirements, most of which have simple logic, such as CRUD, moving bricks, and so on, that can be customized directly by writing SQL
Take an example:
Table :user(id,name,sex,phone,create_time)
Requirement 1: Perform paging query on the user table. Parameter create_time Is mandatory. Optional parameter name Fuzzy match
Implemented in Rocket-API as:
sql = """ select id,name from user where create_time between #{startTime} and #{endTime} ? {name,and name like concat('%',#{name},'%')} """ db.pager(sql)Copy the code
Screenshot from the full Rocket-API:
Description:
- The SQL part is much like the Mybatis syntax, with #{} for parameter substitution,? {} : indicates optional parameter substitution (syntax consistent with mybatis if syntax)
- Db.pager () binds the parameters to SQL
- The source of the parameters is directly HTTP request parameters:
http://localhost:8088/user/page?startTime=2020-07-12 00:00:00&endTime=2020-10-12 00:00:00
, omit parameter receiving, VO definition, etc
Requirement 2: Perform a paging query on the user table, return the user name, books owned by the user (multiple books are separated by commas), mandatory parameter create_time Time range, optional parameter name fuzzy match
Implemented in Rocket-API as:
sql = """
select t1.name,group_concat(t3.name) books
(
select id,name from user where create_time between #{startTime} and #{endTime}
?{name,and name like concat('%',#{name},'%')}
) t1
left join user_book t2 on t1.id = t2.user_id
left join book t3 on t3.id = t2.book_id
group by t1.id
"""
db.pager(sql)
Copy the code
Description:
- If you can do it in SQL, stick to not writing code
Official address: gitee.com/alenfive/ro…