-
创建springBoot项目
-
导入依赖注意要将pojo服务的依赖与导入进来
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.4
org.example
20201121_pojo
1.0-SNAPSHOT
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
- 创建dao层接口
@Mapper
@Repository
public interface UserDao {
List selectAll();
User query(@Param(“id”) int id);
boolean add(User user);
boolean delete(@Param(“id”) int id);
}
- 创建dao层对应的mapper文件
select * from user;
select * from user where id=#{id};
insert into user(name, pwd) values (#{name}, #{pwd});
delete from user where id=#{id};
- 配置application.yml
server:
port: 8080
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.springcloud.pojo
spring:
datasource:
driver-cla