1.31

整合Mybatis

2.创建工程,引入起步依赖

 

 3.编写配置文件

# datasource
spring:
datasource:
url: jdbc:mysql:///springboot?serverTimezone=UTC
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver


# mybatis,如果你是基于注解开发的,那么下面的配置是不用加的
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml # mapper映射文件路径
type-aliases-package: com.itheima.springbootmybatis.domain

# config-location: # 指定mybatis的核心配置文件

package com.itheima.springbootmybatis.mapper;

import com.itheima.springbootmybatis.domain.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

@Select("select * from t_user")
public List<User> findAll();
}

 

posted @ 2024-02-28 23:58  奶油冰激凌  阅读(19)  评论(0)    收藏  举报