1. Write controller code
@Autowired
private TeacherService teacherService;
@GetMapping
public List<Teacher> list(){
return teacherService.list(null);
}
2. Create SpringBoot configuration class
rest style
query use get add post modify put delete delete
create config package under edu package, create MyBatisPlusConfig.java
package com.guli.edu.config;
@Configuration
@EnableTransactionManagement
@MapperScan("com.atguigu.eduservice.mapper")
public class MyBatisPlusConfig {
}
3. Configure the SQL execution performance analysis plug-in
/**
* SQL 执行性能分析插件
* 开发环境使用,线上不推荐。 maxTime 指的是 sql 最大执行时长
*/
@Bean
@Profile({"dev","test"})// 设置 dev test 环境开启
public PerformanceInterceptor performanceInterceptor() {
PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
performanceInterceptor.setMaxTime(1000);//ms,超过此处设置的ms则sql不执行
performanceInterceptor.setFormat(true);
return performanceInterceptor;
}
4. Create a SpringBoot startup class
Create the startup class EduApplication.java, pay attention to the creation location of the startup class ---- put it at the end
@SpringBootApplication
public class EduApplication {
public static void main(String[] args) {
SpringApplication.run(EduApplication.class, args);
}
}
5. Run startup class
//访问地址 http://localhost:8001/eduService/edu-teacher/findAll
Get json data
6. Unified returned json time format
By default, the json time format has a time zone, and is universal standard time, which is eight hours away
from our time . Set in application.properties
#返回json的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
Just