springboot开发一个简答的接口

3 篇文章 0 订阅
2 篇文章 0 订阅

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

教程完毕,看不懂私聊我。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值