Continuing with the previous article, the previous article introduced how the Noy framework operates. This article introduces the simple operations of the Noy framework, using the code generator that comes with the framework to do some additions, deletions, modifications and checks. 1.
Currently, the code that the framework can generate is
2. Chapter 2 The first step requires us to create a table in the database, so that we can use the function of the Noy framework to automatically generate the addition, deletion, modification and query functions corresponding to the table we created.
—I created a new teacher table here
CREATE TABLE `teacher` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
`teacher_name` varchar(30) DEFAULT '' COMMENT '老师姓名',
`teacher_num` varchar(30) DEFAULT '' COMMENT '工号',
`address` varchar(500) DEFAULT '' COMMENT '家庭住址',
`teacher_age` int(3) DEFAULT NULL COMMENT '年龄',
`teacher_sex` char(1) DEFAULT '0' COMMENT '性别(0男 1女 2未知)',
`teacher_birthday` datetime DEFAULT NULL COMMENT '生日',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='老师表';
3. We start the project and find the system tools - code generation - import
and click Edit to change the settings related to the write page button. After setting up, click to generate the code.
4. As needed, just put the generated code into your own project.
We can create a new folder to store the generated code and try to distinguish it from the system for subsequent development.
According to the official website manual, our service and sql related codes should Stored in the system,
we can create a new folder to store it to facilitate subsequent modification and search.
It should be noted that the system automatically generates the system file. We created the teach file ourselves. The main import needs to be changed.
Continue to change the mapper file. The automatically generated mapper file is stored in
the path of the class we save in the project. Change
5, next we integrate the controller part. The official website documents of this department are stored under the admin
. We need to change the import
6. Finally, put our automatically generated front-end page.
Similarly, we also need to change the system for all pages. teach, you can use ctrl+r to replace
this. We are basically done. Now we log in to add a directory and menu and test it.
New
Then it refreshes and it comes out
Then create a new menu to manage the teacher class, that is, do some additions, deletions, modifications, and checks.
The request address and permission identification are as shown in the picture below.
Finally, we can add a piece of knowledge in the teacher management menu under the catalog teacher to add, delete, modify and check functions :
When we added the menu, we gave the request address, which is easy to understand, and also gave a permission @RequiresPermissions("teach:teacher:view").
This permission is for different logged-in users to restrict them from viewing the teacher directory. This permission is in Of course, we can also modify user permissions on the database table on the page, such as adding permissions to manage teachers for ordinary users [click Modify to add the corresponding permissions]
If the corresponding permissions are added, they will also be reflected in the database table, such as:
In the same way, when we perform corresponding operations on the page, its permissions will also be added to the corresponding database. For example:
we add a button under the menu under the teacher directory to query teachers .
The corresponding database will have one more permission.
At this time, we only need If ordinary users are given the query permission, the corresponding database will also be added. At the same time, if we log in as an ordinary user, we can have the teacher's query function.
At this time, we switch the user to ordinary users, which is perfect. Ordinary users also have the query function.