查询表中所有的数据
1.添加mapper扫描配置
@Configuration @MapperScan("com.atguigu.eduservice.mapper")
2.控制类中添加service注解,添加查询方法
package com.atguigu.eduservice.controller;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduTeacherService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 讲师 前端控制器
* </p>
*
* @author testjava
* @since 2020-08-11
*/
@RestController
@RequestMapping("/eduservice/teacher")
public class EduTeacherController {
//访问地址:http://localhost:8001/eduservice/teacher/findAll
//把service注入
@Autowired
private EduTeacherService eduTeacherService;
//1 查询讲师表所有数据
//rest风格
@GetMapping("findAll")
public List<EduTeacher> findAllTeacher(){
//调用用service的方法实现查询所有的操作
List<EduTeacher> list = eduTeacherService.list(null);
return list;
}
}
3.添加启动类
package com.atguigu.eduservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EduApplication {
public static void main(String[] args){
SpringApplication.run(EduApplication.class,args);
}
}