第一步:在application.properties中添加数据库配置
server.port=8081 #==============================数据库相关配置======================================== spring.datasource.driver-class-name =com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/online_yspan?useUnicode=true&characterEncoding=utf-8&useSSL=false spring.datasource.username=root spring.datasource.password=root #使用阿里巴巴druid数据源,默认使用自带的 #spring.datasource.type =com.alibaba.druid.pool.DruidDataSource #开启控制台打印sql mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl # mybatis 下划线转驼峰配置,两者都可以 #mybatis.configuration.mapUnderscoreToCamelCase=true mybatis.configuration.map-underscore-to-camel-case=true #配置扫描 mybatis.mapper-locations=classpath:mapper/*.xml #配置xml的结果别名 mybatis.type-aliases-package=work.yspan.online.domain
第二步:创建VideoMapper.xml 以及mapper下的VideoMapper接口
VideoMapper.xml
select * from video
第三步:创建service下的VideoService和VideoServiceImpl
VideoService
public interface VideoService {
List
VideoServiceImpl
@Service
public class VideoServiceImpl implements VideoService {
@Autowired
private VideoMapper videoMapper;
@Override
public List
第四步:创建controller下的VideoController
VideoController
@RestController
@RequestMapping("video")
public class VideoController {
@Autowired
private VideoService videoService;
@RequestMapping("list")
public Object listVideo(){
return videoService.listVideo();
}
}
第五步:启动类添加mapper扫描
效果截图:



