Enhanced SpringBoot rapid development tools
LOCATION: https://gitee.com/sanri/web-ui
advantages: It is a common component web configuration, plug and play, may be used for a new project or private life. Is a supplement SpringBoot rapid development, it built a lot of configuration to simplify the development, follow the convention over configuration principle.
It solves the problem:
- Fixed input and output formats
- For the Controller returns do not care about packaging type, the type of return you need it, to insert a single table operations can return void directly
- If the project does not meet the operational error or a third-party call, you can use an exception or assertion thrown, we will return to intercept into a unified format
- Comes parameter space filtering function, you can also define harmony special characters
- Support checker, you have to help you set up two group
- Support large file upload slices
BUG can be found mention Issue, you can send me an e-mail, you can add my QQ, you can into the 9420 technical group discussion.
Author QQ: 2441719087
Author E-mail: [email protected]
9420 Technical exchange group: 645 576 465
On the micro letter: sanri1993-
Item Function
I opened a new project, summed up the resulting development experience in the past four years, it has functions
Fixed input and output formats
// 普通输出格式 @Data public class ResponseDto<T> implements Serializable { // 0 字符串表示成功,否则失败 private String code = "0"; private String message; private T data; } // 分页输出格式,是包裹在普通输出格式中的,PageResponseDto 做为 data 属性 @Data public class PageResponseDto<T> { private List<T> rows; private Integer total; } // 分页输入格式 @Setter public class PageParam { private String pageNo; private String pageSize; }
For the Controller returns do not care about packaging type, the type of return you need it, to insert a single table operations can return void directly
Example 1:
@PostMapping("/insertUser") public void insertUser(User user){ xxxService.insert(user); }
It will return such a data structure
{ "code":"0", "message":"ok", "data":null }
Example Two:
@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 Three:
For paged data processing
@GetMapping("/queryUserPage") public PageResponseDto<User> pageQuery(PageParam pageParam,Map<String,String> queryParams){ PageHelper.startPage(pageParam.getPageNo(),pageParam.getPageSize()); Page page = (Page) xxxService.pageQuery(queryParams); List result = page.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":[{...},{...}] } }
If the project does not meet the operational error or a third-party call, you can use an exception is thrown, we will return to intercept into a unified format
Example 1:
if(业务条件不满足){ throw BusinessException.create("业务提示信息"); }
It will return a data structure, code is randomly generated
{ "code":"234234", "message":"业务提示信息", "data":null }
Example Two:
An exemplary method of custom code
if(业务条件不满足){ throw BusinessException.create("E007","业务提示信息"); }
It will return such a data structure
{ "code":"E007", "message":"业务提示信息", "data":null }
Example Three:
Method Two exemplary custom code
// 配置异常代码 public enum SystemMessage implements ExceptionCause<BusinessException> { SIGN_ERROR(4005,"签名错误,你的签名串为 [%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); } }
Use exceptions
if(业务条件不满足){ throw SystemMessage.SIGN_ERROR.exception("签名串"); }
It will return such a data structure
{ "code":"4005", "message":"签名错误,你的签名串为 [签名串]", "data":null }
Do you think it's such a point capability it, it also comes with a space filtering parameters, you can also define the special character harmony
You only need to inject a processor, it can work, injecting follows
@Bean("paramHandler") public Function paramHandler(){ return param -> param.replace("<","《"); }
Comes with a date conversion (input) function can be supported date formats
final String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.S"};
This is now fixed three formats, the latter will release allows users to configure their own
Support checker, have to help you set up two group, can be used directly
public interface Insert { } public interface Update { }
Instructions for use
The introduction of the package or download jar package file
<dependency>
<groupId>com.sanri.web</groupId>
<artifactId>web-ui</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Enable the rapid development
@EnableWebUI
Little promotion
Writing is not easy, I hope the support of open source software, and my gadgets, welcome to gitee point star, fork, put bug.
Excel common import and export, support Excel formulas
blog address: https://blog.csdn.net/sanri1993/article/details/100601578
gitee: https://gitee.com/sanri/sanri-excel-poi
Use the template code, the gadget generate code from the database, and some projects can often be used in the
blog address: https://blog.csdn.net/sanri1993/article/details/98664034
gitee: https://gitee.com/ sanri / sanri-tools-maven