In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to build a SpringBoot+MyBatis+Freemarker project", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to build a SpringBoot+MyBatis+Freemarker project" this article.
Now the Java web project has used more SpringBoot to build, one is that its configuration is simpler, the second is that the popular service architecture Springcloud is based on SpringBoot to achieve specific technical details, MyBatis is also our commonly used semi-automatic persistence layer framework. Today, the editor is going to lead you to build a project based on SpringBoot and MyBatis and the common high-performance page rendering framework Freemarker to build a user information query display project.
Generate the project schema file. Visit the SpringBoot official website to generate the documents we need for the Maven project. There are mainly several attributes to select and fill in:
1. Choose the way the project is built, and here we choose Maven project. two。 Enter the Group and Artifact attributes of the Maven project coordinates. If you need to modify other attributes of the project, click More options to modify the JDK version and other project description information. Here, we will default. 3. Find the dependency package you need. Here we choose the driver package for MySql and the dependency package for MyBatis and Freemarker.
Import the downloaded project file to build. The main process is as follows:
1. Extract the file you just generated to the specified directory and import the project as maven using eclipse.
two。 Find the application.properties file in the src/main/resouces directory and open it for editing. In the file, we need to configure the application's startup port, data source configuration information, and freemarker properties.
3. Right-click pom.xml on run as-> Maven Install, and we can write the background service class if there is no error in the build.
Configure the SpringBoot profile. We need to configure the name and port of the project project, followed by the data source used by MyBatis, as well as the property configuration of Freemarker. The specific parameter properties of this case are shown in the figure.
Writing entity classes and service-related interfaces required by MyBatis. First of all, we have created a database named test and created a new t_user user table in it. We need to create new entity classes, service classes and Mapping mapping files based on this table. There are four main documents:
1. Entity class file corresponding to User data table
2.UserDao data interface class
3. Data service interface corresponding to UserService entity class
4. The implementation class of the UserServiceImpl interface class needs to use @ Service ("xxx"), and the Controller needs this class.
5. Create a UserMapper.xml Sql query mapping file. The mybatis.mapperLocations specified in the project configuration file.
Write requests and pages that implement the interface of the Controller class. Create two different Controller classes, one to jump to the Freemarker page and the other to return the corresponding JSON information. The details are as follows:
1. Create a UserController class to return the user's json format data using @ RestController and @ RequestMapping.
two。 Create an IndexController class to return to the corresponding Freemarker page with @ Controller and @ RequestMapping.
3. Create a Freemarker front-end page index.ftl with the name of create ModelAndView ("page name") without a suffix.
Configure the startup class and start it. You need to configure three annotations in the startup class of this project, as follows:
1.@SpringBootApplication is responsible for scanning the loaded project context, and the default scan package is the current directory and subdirectories.
2.@MapperScan is responsible for scanning the dao class that MyBatis is responsible for.
3.@ComponentScan is responsible for scanning the specified range of packets.
These are all the contents of the article "how to build a SpringBoot+MyBatis+Freemarker Project". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.