Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the introduction and usage of Martian

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

The introduction and usage of Martian, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Project profile

Martian is a Java development framework for declarative API programming (DAP)

Using HttpServer as a http service completely breaks away from Web containers and Servlet like Tomcat, and at the same time reduces several dependencies on the project.

Declarative API turns Controller into an interface, which reduces the workload of development

Have most of the functions of other web frameworks, such as AOP,IOC, declarative transactions, exception listening, etc.

Has a self-developed semi-ORM persistence layer framework and is naturally integrated into Martian

If you don't like HttpServer, we also provide Tomcat initiator.

Project ecology

[distributed components] Martian-cloud

[gateways and other components] Martian-gateway

[more components] in planning

Official document

Http://mars-framework.com/doc.html?tag=martian

Use the example

Https://github.com/yuyenews/Mars-Example

Project characteristics 1. Declarative API

You only need to add a note to your interface to provide an interface, and we also support traditional Controller writing.

@ MarsApi (refBean= "name of bean to be referenced") public interface TestApi {return type selectList (TestDTO testDTO);} II. Single table addition, deletion, modification, query without sql// query a data according to the primary key @ MarsGet (tableName = "userinfo", primaryKey = "id") the entity class selectById (int id) to be returned by public abstract; / / add @ MarsUpdate (tableName = "userinfo", operType = OperType.INSERT) public abstract int insert (entity object parameter) / / single table deletes @ MarsUpdate (tableName = "userinfo", operType = OperType.DELETE,primaryKey = "id") public abstract int delete (int id) according to the primary key; / / single table modifies @ MarsUpdate (tableName = "userinfo", operType = OperType.UPDATE,primaryKey = "id") public abstract int update (entity object parameter) according to the primary key; third, parameter verification requires only one comment

Just add a note to the field in the parameter object of the API interface (note on the field of VO)

/ / cannot be nullable and has a length of 2-3 bits @ MarsDataCheck (notNull = true,maxLength = 3L ·min length = 2L, msg = "id cannot be nullable and must be between 2-3 digits") private Integer id / / regular check @ MarsDataCheck (reg = "^ (?! [0-9] + $) (?! [a-zA-Z] + $) [0-9A-Za-z] {6je 12} $", msg = "password cannot be empty and must be a combination of 6-12 digits and letters") private String password

How does the front end get a hint?

It is fine to request an API normally. If the verification fails, you will get such a json.

{"error_code": 1128, "error_info": "prompt text"} IV. Exception listener

Usually when we write code, we need to add try {} catch () {} to each Controller method, so that the json string can be returned normally in case of an exception.

Spring has an ExecptionHandler to solve this problem, and Martion also provides a corresponding solution.

The solution is not to worry about anything. If something goes wrong, the following json string will be returned to the front end automatically.

{"error_code": 500, "error_info": "exception prompt"} five or one-line annotations to solve distributed locks

Add RedisLock comments to the method to be locked

@ RedisLock (key = "define a key yourself") public int insert () {return 1;} is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report