preface
With nothing to do, the entire Java project quickly developed scaffolding.
The body of the
A list,
Chewing is a simple fast development scaffolding for Java projects. Not only suitable for small partners who need to develop small projects, but also suitable for beginners to learn some common technology.
Second, the source
- Github:github.com/jingqueyimu… .
- Gitee:gitee.com/jingqueyimu… .
Core technology
1, the back end
- SpringBoot: Web application framework.
- MyBatis: Persistence layer framework.
- MySQL: relational database.
- Redis: cache database.
- RabbitMQ: Message queue middleware.
2, the front end,
- Thymeleaf: template engine.
- Bootstrap: UI framework.
Iv. Environment deployment
1. Preparation
- JDK 1.8
- MySQL 5.7
- Maven 3.x
- Redis
- RabbitMQ
2. Required configuration
- Application. Properties configuration file: database, Redis, RabbitMQ, mailbox, etc.
- Config/myconfig properties configuration file: system related to custom configurations.
V. Project introduction
1. File structure
SRC/main/Java. | - com jingqueyimu / / comments | -- - | - an annotation aspect / / plane | -- - | - constant / / config / / configuration constants | - context / / context | -- - | - exception / / controller / / control layer abnormal | | - factory / / factory - filter/filter / | | - handler / / processor - init / / initialization | - Interceptor / / interceptor | - mapper / / persistence layer | -- - | - mq / / model / / data model message queue scheduling | | - the schedule / / - service / | - util / / tools/services layer MyAppcation. Java / / application startup class SRC/main/resources | - config / / config file | - mapper / / mapping file | | - static / / static file - templates / / page file Properties // Application configuration file Quartz. Properties // Scheduling configuration fileCopy the code
2. Code description
(1) Routing
- / API/XXX: user login is required.
- /console/ XXX: the administrator needs to log in, except for some interfaces such as login and logout.
(2) Interface specifications
- Page request: GET, URL parameters.
- Interface request: POST, JSON parameters.
(3) Database initialization
- The initial configuration file is config/dbinit.json.
- Configure the initialization identifier and SQL statement.
Initialization example:
[ { "initKey": "site_config_20210110", "sqls": [ "INSERT INTO t_site_config (id, code, name, content, description, public_flag, gmt_create) VALUES(NULL, 'site_record_no', 'website for the record number', '< a href = "https://beian.miit.gov.cn\" class = \ "ml - 2 \" target = \ \ "_blank \" > record number < / a >', 'website for the record number, true, NOW());" ] } ]Copy the code
(4) File upload and download
- Upload a single file: /file/upload.
- Upload multiple files: /file/uploads.
- Download the file: /file/download.
(5) Excel import and export
- Excel import and export methods: excelutil.importexcel (), excelutil.exportExcel ().
- Excel import and export processor interface: IExcelImportHandler, IExcelExportHandler.
Import example:
String msg = null; try { String[] keys = new String[] {"username", "realName", "mobile"}; msg = ExcelUtil.importExcel(file.getInputStream(), keys, new IExcelImportHandler() { @Override public void handle(JSONObject data) { if (stringutils.isblank (data.getString("username"))) {throw new RuntimeException(" username cannot be empty "); } if (stringutils.isblank (data.getString("mobile"))) {throw new RuntimeException(" mobile number cannot be empty "); } // business processing}}); log.info(msg); } catch (IOException e) { e.printStackTrace(); }Copy the code
Export example:
ServletOutputStream os = null; Try {String fileName = "User list "; . List<User> List = userservice. List (params); / / header String [] headers = new String [] {" id ", "user name", "name", "phone number", "email", "registry", "registration time", "the last login time", "whether the VIP"}; os = response.getOutputStream(); // Export ExcelUtil. ExportExcel (fileName, list, headers, OS, new IExcelExportHandler<User>() { @Override public List<Object> handle(User user) { List<Object> rowDatas = new ArrayList<>(); rowDatas.add(user.getId()); rowDatas.add(user.getUsername()); rowDatas.add(user.getRealName()); rowDatas.add(user.getMobile()); rowDatas.add(user.getEmail()); rowDatas.add(RegisterType.getEnum(user.getRegisterType()).getValue()); rowDatas.add(DateUtil.format(user.getRegisterTime(), "yyyy-MM-dd HH:mm:ss")); rowDatas.add(user.getLastLoginTime() == null ? "" : DateUtil.format(user.getLastLoginTime(), "yyyy-MM-dd HH:mm:ss")); rowDatas.add(Boolean.TRUE.equals(user.getVipFlag()) ? "Yes" : "No "); return rowDatas; }}); } catch (IOException e) { e.printStackTrace(); } finally { ... }Copy the code
(6) Get the dictionary
- Get a single dictionary: /common/dict.
- Get multiple dictionaries: /common/dicts.
(7) Context information
- UserContext: UserContext information.
- AdminContext: Administrator context information.
(8) Scheduling
- Added Scheduling tasks: BaseJob inheritance.
- Scheduling interface
- To execute a scheduling task, run /console/schedule_job/run.
- To change the scheduling status, run the /console/schedule_job/update_status command.
- Change the scheduling frequency to /console/schedule_job/update_cron.
(9) Notes
- @lock: distributed Lock.
- @perm: Indicates the interface that requires administrator rights.
(10) Configuration file
- Due to personal habits, the project uses the Properties configuration file. For those who are used to using the YML configuration file, please modify it manually.
- If you want to load custom yml configuration file, you can use the project source of YAML attribute of the factory class: YamlPropertySourceFactory.
Code examples:
@Component
@ConfigurationProperties(prefix="test")
@PropertySource(value="classpath:config/test.yml", encoding="UTF-8", factory=YamlPropertySourceFactory.class)
public class TestYmlConfig {
...
}
Copy the code
(11) Attribute name suffix matches query conditions
A BaseService method that takes a JSON object as its parameter can match the query condition by adding a suffix after the attribute name.
- Xxx_begin: Greater than or equal to xxX_BEGIN.
- Xxx_end: less than or equal to xxx_end.
- Xxx_in: IN query.
- Xxx_like: fuzzy query.
- Xxx_llike: left fuzzy query.
- Xxx_rlike: Right fuzzy query.
- Other: equal to.
- If the property value is null, the query will not be performed.
Code examples:
@Test
public void test() {
JSONObject params = new JSONObject();
params.put("username_like", "test");
List<User> user = userService.list(params);
System.out.println(user);
}
@Test
public void test2() {
JSONObject params = new JSONObject();
params.put("username_in", Arrays.asList("test"));
List<User> user = userService.list(params);
System.out.println(user);
}
Copy the code
(12)…
6. Demo diagram
1, the front desk
2, the background,
conclusion
Currently, this course offers the usual range of activities (really the liver doesn’t move). However, it will continue to improve and add new features. There will also be a microservice version if there is time.
Stay tuned ~
Communication area
WeChat public number: jing is a mesh < br / > personal blog: < a href = "https://www.jingqueyimu.com" > surprised but an item < / a >Copy the code