In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Spring boot build personal blog how to achieve list, details, paging function, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Editing tool: IDEA
Working with frames: springboot
The first step is to create a springboot project named blog
Create a springboot project
Named blog
The second step is to import dependency
Hot deployment dependency
Step 3, configure application.properties
The fourth step is to configure the hot deployment of the project (no need to restart the service to modify the file)
Since we have imported devtools dependencies, we only need to configure ide
① settings- > Build,Execution,Deployment- > compiler, check
② hold down the key combination "Shift+Ctrl+Alt+/" and select "Registry"
Let's start coding.
I. configuration of resource files
Because of the springboot project created with idea, we cannot create the class file after initialization. I need to configure the project directory as follows
Select the model created by yourself
Open the directory to java, click sources, and that's fine.
Create a test demo to see if the system can run
Test code content
The project test success page will return hello
Now that the project is running, we can move on to the next step by importing all the front-end pages we have prepared into the project to test whether they can be accessed properly.
The directory structure after import is as follows
Enter the access address and you can see the static page that I prepared in advance.
III. Prepare the basic structure
① creates the data table structure and imports the data table I prepared in advance:
② creates a project hierarchy (controller,entity,bizlogic)
③ creates basic entities
④ because I am using mybatis's generic mapper, I need to create a generic mapper. This mapper must be placed outside the package scan. It is recommended to put it in the same level directory as bootapplication.
Tool classes that ⑤ needs to use to create a generic mapper
Four-tier and three-tier structure are developed successively.
Entity: first of all, I develop the article list, create the corresponding entity information as follows, and omit the get,set method.
Dao creates the corresponding dao that inherits the general mapper interface. If you only need to add, delete, change and query the interface, you do not need to write any method.
Bizlogic: create a business logic layer to implement specific business operations
There are only two methods in this method, one is to get the list of articles, but to get the details of the articles.
Controller
There are also two control methods in controll.
Front-end page modification:
Templates contains two pages, one is the list page and the other is the details page
First, let's deal with the list page and use the freemarker collection to traverse the data.
The set variables in this are consistent with the variables passed in the background.
The details page is the same as the list page, except that you don't need to traverse, just use variables.
Open the browser. View the list page
Click the title to see the details page
At this point, the basic display function of the blog has been completed, and similar operations can be done on other pages, but if there are too many articles on the page, you need to be paged, and finally integrate the PageHelper plug-in to achieve the paging function.
Add the following code to the original list method
The paging method for front-end pages is as follows
Click the paging button to re-request background data
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.