Automatic construction of small and medium-sized projects with 0 code based on springboot

Familiar with memory 2021-01-21 14:39:48
automatic construction small medium-sized medium


brief introduction

spring-boot-quick-project-fars Full name spring-boot-quick-project-front-and-rear-separation It's based on SpringBoot,MyBatis And so on CSD(Controller-Service-DAO) Project for layer , Used to quickly build small and medium-sized API、RESTful API project . Easy to use , Stable and fast operation , Get rid of repetitive labor , Focus on writing business code . Here is a simple video Demo, Based on this project, we can realize a simple set of API,0 Code writing , Realize the operation of adding, deleting, modifying and querying a single table .

Demo video

Click on the picture to open the demo video , If you can't open it, you need to go over the wall ~~

features

  • Best practice project structure 、 The configuration file 、 Streamlined POM
  • Unified response result encapsulation and generation tool
  • Unified exception handling
  • Simple interface signature authentication
  • Abstract encapsulation of common basic methods
  • Use Druid Spring Boot Starter Integrate Druid Database connection pool and monitoring
  • Use FastJsonHttpMessageConverter, Improve JSON Serialization speed
  • Integrate MyBatis、 Universal Mapper plug-in unit 、PageHelper Paging plug-ins , Realize single table business zero SQL
  • Provide code generator to generate corresponding Entity、Mapper、MapperXML、Service、ServiceImpl、Controller And so on
  • Controller The template provides... By default POST and RESTful Two sets , According to the demand in application-init.properties Configure yourself in the configuration file project.controller.ftl.model, By default POST The template of the way .
  • The code template can be extended according to the actual needs of the project , Because every company's business is different , So it only provides some basis for comparison 、 Common templates , The main idea is to provide an idea To reduce repetitive code writing .
  • In the actual use of the project , You can write a large number of templates based on the abstraction of the company's business . in addition , Using templates also helps keep the team's code style uniform

Quick start

  1. Clone the project locally
  2. Yes src/resoucres Under the application-dev.properties,application-init.properties To configure , Mainly JDBC, Project package name, etc
  3. Yes src/test The code generator in the package CodeAuthGenerator Medium main Test methods to configure , The main task is to configure the name of the table to be generated , Generate code based on the table name
  4. If you just want to test , have access to src/test/resources In the catalog sq-user.sql, Otherwise, ignore the step
  5. Enter table name , function CodeAuthGenerator.main() Method , Generate basic code ( You may need to refresh the project directory to get it out )
  6. Expand on the basic code according to the business
  7. Configuration file for development environment application-dev.properties To configure , Start the project .

Development Suggestions

  • Table name , Lowercase is recommended , Underline multiple words
  • Entity Inner member variable corresponds to the number of table fields , To extend a member variable ( For example, linked table query ) Recommend creating DTO, Otherwise, add... To the extended member variable @Transient annotation , For details, see Universal Mapper Plug in documentation
  • It is suggested that if the business fails, it should be used directly ServiceException("message") Throw out , The unified exception handler encapsulates the response result of service failure , such as throw new ServiceException(" The mobile number has been registered "), It will be packaged directly as {"code":400,"message":" The mobile number has been registered "} return , You don't have to deal with it yourself , Throw it out
  • If you need tools, it is recommended to start with apache-commons-* and guava In looking for , There's no way to recreate the wheel or introduce the class library , Try to streamline the project
  • Development specifications are recommended to follow ( Alibaba Java Development Manual )
  • It is recommended to use it inside the company ShowDocSpringFox-Swagger2RAP Wait for open source projects to write 、 management API file

Some of the open source projects that the project relies on

XDoc Quick document building framework

function

be based on java Comments generate interface documents Annotations support extensions The interface framework supports extensions The default support markdown And offline / On-line html Document of equal format The default support spring mvc standard The default support spring-boot Direct inline boot

matters needing attention

stay Controller Layer of @RequestMapping Values in annotations , Can't use "/“ start , Otherwise, the generated automatic document cannot be tested online for example :@RequestMapping(”/user") Need to be written @RequestMapping(“user”) in addition , Cannot configure... In configuration file spring.resources.add-mappings=false In the build environment XDoc, It may cause jar The bag is a little bigger Such as Controller The method parameter in is POJO object ( for example User object ), Then use XDoc It's troublesome to pass the value test If you need to test , And then they spread it JSON character string , And add... Before the object of the method RequestBody annotation

 @PostMapping("add")
@ResponseBody
public ResultModel add(@RequestBody User user) {
userService.insert(user);
return ResultModel.success();
}

Found by testing , This method cannot be used XDoc Transfer object's JSON String test . XDoc The front-end test will treat the object as String transmitted for example : In the test Address of the interface : user/add, stay XDoc Interface

{
"username": "123456",
"password": "123456",
"salt": "12555",
"age": 21,
"status": 1
}

stay XDoc tests , An assignment will be made , And bring the parameter name with it , As key=value Pass on to Controller Layer method . So in fastJson When parsing, the string you get is :

user={ "username": "123456", "password": "123456", "salt": "12555", "age": 21, "status": 1}

So the following exception appears

nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual ident, pos 0, fastjson-version 1.2.49

Not yet XDoc Other aspects of the framework Bug test , If you have time later , It might be for XDoc Make some changes

visit

After running the project locally , Type... Directly into the browser http://localhost:8080/xdoc/index.html Just visit

Click on the test on the far right

Parameters can be input for testing

Reference items

spring-boot-api-project-seed

other

If you need new features , Welcome to mention Issues, Will consider joining . Thank you for your Star & Fork Support for .

Address of the project

https://github.com/chenhaoxiang/spring-boot-quick-project-all

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Familiar with memory]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121143722283p.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云