1、配置数据库
先查看数据库时区设置:show variables like ‘%time_zone%’;
更改时区设置:set global time_zone = ‘+8:00’;
2、IDE
勾选springweb项目,sql选择mybatis
2、然后就创建好了一个springboot的demo;
3、目录结构:
**controller**
@RestController
public class IndexController {
@Autowired
UserService userService;
@GetMapping("/show")
public List<User> getUser(int age){
return userService.getUser(age);
}
@RequestMapping("/index")
public Map<String,String> index(){
Map map=new HashMap<>();
map.put("北京","北方城市");
return map;
}
}
@Mapper
public interface UserMapper {
@Select("SELECT id,username,age,phone,email FROM USERS WHERE AGE=#{age}")
List<User> getUser(int age);
}
public class User {
private int id;
private String username;
private Integer age;
private Integer phone;
private String email;
public interface UserService {
List<User> getUser(int age);
}
@Service
public class UserServiceImpl implements UserService{
@Autowired
UserMapper userMapper;
@Override
public List<User> getUser(int age){
return userMapper.getUser(age);
}
}
@SpringBootApplication
@ComponentScan(basePackages = {"com.athm.controller","com.athm.service"})
@MapperScan(basePackages = {"com.athm.dao"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
配置文件
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
server:
port: 8888
servlet:
context-path: /demo
教程完毕,看不懂私聊我。