Springboot Developed Custom Supply

Enhance SpringBoot rapid development tool

Project address: https://gitee.com/sanri/web-ui
Advantages: This is a web universal configuration component, plug and play, can be used for new projects or private work. It is a supplement to the rapid development of SpringBoot. It has a large number of built-in configurations to simplify development and follows the principle of convention over configuration.

The problem it solves:

  • Fixed the input and output format
  • For the return in the Controller, don’t care about the packaging type, return the type you need You can directly return void for insert single-table operations.
  • If there is a business operation in the project that does not meet or a third-party error occurs, you can use exceptions or assertions to throw, and we will intercept them and return them in a unified format.< /li>
  • With parameter space filtering function, you can also define special character harmony
  • Support validator, two groups have been set up for you
  • Support large files Multipart upload

If you find a bug, you can mention Issue, you can send me an email, you can add my QQ, you can enter the 9420 technical group for discussion.

Author QQ: 2441719087< /p>

Author’s mailbox: [email protected]

9420 Technical Exchange Group: 645576465

Author’s WeChat: sanri1993-
Insert picture here Description

Project function

I opened a new one The project summarizes the development experience gained in the past 4 years. It has the following functions

  • Fixed input and output format

    // Ordinary Output format @Datapublic class ResponseDto implements Serializable {// 0 string means success, otherwise it fails private String code = "0"; private String message; private T data;}// The paging output format is wrapped in normal output In the format, PageResponseDto is used as the data attribute @Datapublic class PageResponseDto {private List rows; private Integer total;}// Pagination input format @Setterpublic class PageParam {private String page No; private String pageSize;}
  • For the return in the Controller, you don’t need to care about the packaging type, just return the type you need, and you can directly return void for the insert single table operation.

    Example 1:

    @PostMapping("/insertUser")public void insertUser(User user){ xxxService.insert(user );}

    It will return this data structure

    { "code":"0", "message":"ok", "data" :null}

    Example 2:

    @GetMapping("/queryUserById")public User queryUserById(Integer userId){ xxxService. queryUserById(userId);}

    It will return such a data structure

    { "code":"0", "message":"ok", "data":{ "userId":1, "username":"9420" }}

    Example 3:

    Processing of paging data< /p>

    @GetMapping("/queryUserPage")public PageResponseDto pageQuery(PageParam pageParam,Map queryParams){ PageHelper.startPage(pageParam.getPageNo(),pageParam. getPageSize()); Page page = (Page) xxxService.pageQuery(queryParams); List result = pag e.getResult(); long total = page.getTotal(); return new PageResponseDto(result,total);}

    It will return such a data structure

    { "code":"0", "message":"ok", "data":{ "total":100, "rows":[{...},{...}] }}< /pre>
  • If there is a business operation inconsistent in the project or a third-party call error occurs, an exception can be thrown, and we will intercept it and return it in a unified format

    Example 1:

    if (business conditions are not met) {throw BusinessException.create("Business tips");}

    It will Return to such a data structure, the code is randomly generated

    { "code":"234234", "message":"Business prompt information", "data":null}

    pre>

    Example two:

    Custom code example method one

    if (business conditions are not met) {throw BusinessException .create("E007","Business prompt information");}

    It will return such a data structure

    { "code":"E007" , "message":"Business reminder information", "data":null}

    Example three:

    Custom code example method two

    // Configure exception code public enum SystemMessage implements ExceptionCause {SIGN_ERROR(4005, "Signature error, your signature string is [%s]"),; ResponseDto responseDto = new ResponseDto(); private SystemMessage(int returnCode,String message){ responseDto.setCode(returnCode+""); responseDto.setMessage(message);} public BusinessException exception(Object...args) {return BusinessException.create(this ,args); }}

    Usage exception

    if (business conditions are not met) {throw SystemMessage.SIGN_ERROR.exception("signature string");}< /pre> 

    It will return this data structure

    { "code":"4005", "message":"Signature error, your signature string is [Signature String]", "data":null}
  • Do you think it’s just as capable? It also comes with parameter space filtering function, and you can also define special characters to be harmonious

  • p>

    You only need to inject a processor and it will work. The injection method is as follows

    @Bean("paramHandler")public Function paramHandler(){ return param -> param.replace("<","《");}
  • With its own date conversion (input) function, the date formats that can be supported are

    final String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss. S"};

    Now these three formats are fixed, and we will let users configure them later.

  • Support validator, already help you After setting up two groups, you can use them directly

    public interface Ins ert {}public interface Update {}

Instructions for Use

Import the package or download the jar package file

< pre class="xml"> com.sanri.web web-ui 1.0-SNAPSHOT

Enable rapid development

@EnableWebUI

A little promotion

The creation is not easy, I hope it can be supported Download my open source software and my gadgets, welcome to gitee to point stars, fork, and raise bugs.

Excel general import and export, support Excel formula
Blog address: https://blog.csdn.net/sanri1993/article/details/100601578
gitee: https://gitee.com /sanri/sanri-excel-poi

Use template code to generate code from the database, and some small tools that can be used frequently in projects
Blog address: https://blog.csdn.net /sanri1993/article/details/98664034
gitee: https://gitee.com/sanri/sanri-tools-maven

Leave a Comment

Your email address will not be published.