In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
one。 Create Module under the project you set up and select Spring initializr to create.
two。 Select: Maven Project (the project's build tool) at Type
three。 Check web,mybatis,mysql when creating dependencies (this depends on your personal needs, you can choose)
The established project structure is as follows:
Note: application.properties and application.yml are the same thing and are the core configuration files of the project.
The contents are as follows:
# connecting to the database
Spring.datasource.url=jdbc:mysql://localhost:3306/smbms
Spring.datasource.username=root
Spring.datasource.password=1234
Spring.datasource.driverClassName=com.mysql.jdbc.Driver
# introducing the configuration file of mybatis
Mybatis:
Mybatis.mapper-locations=classpath:mapper/*.xml
Mybatis.type-aliases-package=com.example.sprboot.pojo
Corresponding pom.xml file
4.0.0
Com.examplespringboot0.0.1-SNAPSHOTjarspringbootDemo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.5.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.mybatis.spring.boot mybatis -spring-boot-starter 1.3.0 mysql mysql-connector-java com.alibaba fastjson 1.2.49 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-maven-plugin
The corresponding interface UserMapper is as follows:
@ Repository
Public interface UserMapper {
List getList ()
}
Service is as follows:
Public interface UserService {
List getList ()
}
Impl is as follows:
@ Service
Public class UserServiceImpl implements UserService {@ Resourcebr/ > @ Resourcebr/ > @ Override
Return userMapper.getList ()
}
}
Create a folder mapper in resources and put the mapper.xml file in it. The code is as follows:
Work number
User name
Name
Gender
Birthday
Telephone
Address
Creation time
There is a th tag here, and you need to introduce a
And introduce the corresponding jar package in pom.xml (jstl expression cannot be used in html)
You can expand the knowledge of thymeleaf.
The controller code is as follows:
@ Controller
Public class UserController {@ Resourcebr/ > @ Resourcebr/ > @ RequestMapping ("/")
List list=userService.getList ()
Model.addAttribute ("users", list)
System.out.println (list)
Return "/ index.html"
}
}
Note: many mistakes may be reported during the transfer, which are basically due to errors in the use of annotations. I hope you can be more careful.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.