前提配置,一切前提
一般都是自动导入
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
boot多了一个application.properties。很重要
二.application.properties
server.port:更改端口号
server.port= 8081
#?????
spring.datasource.username=root
spring.datasource.password=
spring.datasource.url=jdbc:mysql://localhost:3306/spring?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
sql mapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jia.spring06.dao.UserDao">
<insert id="updateInsert" parameterType="com.jia.spring06.pojo.User">
insert into users (id,name,age) values(#{id},#{name},#{age});
</insert>
<select id="queryById" resultType="com.jia.spring06.pojo.User" parameterType="int">
select *from users where id=#{id};
</select>
<delete id="updateDel" parameterType="int">
delete from users where id=#{id};
</delete>
<select id="findNumbers" resultType="int">
insert count(*) from users;
</select>
<select id="queryAll" resultType="com.jia.spring06.pojo.User">
select *from users
</select>
</mapper
三.启动类
@SpringBootApplication:核心注解,作用是开启自动配置,千万别改
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Spring06Application {
public static void main(String[] args) {
SpringApplication.run(Spring06Application.class, args);
}
}
四.了解各层
- domain:相当于实体类(entity),
- service:业务代码
- controller:控制层
其他的都和spring差不多,springboot完全就是玩注解
底层就是spring