Project foundation
170 words
One minute
Using SpringBoot to build a basic project
The steps to initialize SprigBoot using idea
- Using
spring initializer
initialize springboot project
- Choosing
jdk 1.8
- Choosing
springboot 2.1.5
- Setting root path and package name:
com.imooc.dianping
- Introducing 3 maven jar package.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
|
- Adding belows in properties
1
2
3
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
|
Introducing Mybatis
the steps to introduce mybatis:
- Creating
mapping
under resources
,creating dal
, model
, service
under java
.
application.properties
1
2
3
4
5
6
7
8
9
10
11
|
server.port=8090
mybatis.mapperLocations=classpath:mapping/*.xml
spring.datasource.name=dianping
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dianping?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
#使用druid数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.jdbc.Driver
|
- Creating
dianping
database
- Creating
user
table
The steps building basic services
- Creating
userModel
related mapping
- Editing
annotation
in the main class
- Editing controller,service,do
- Introducing front-end static test page
- Accessing the front-end
thymeleaf
dynamic page
- Defining generic return type, generic error type, generic exception type, exception error enum
- Defining exception handling and add 404 handling methods