当前位置:   article > 正文

springboot教程第一课_服务搭建及接口开发_接口挡板开发

接口挡板开发

目录

安装开发工具IDEA

新建springboot项目

添加restfull接口

启动项目验证


安装IDEA并下载JDK到本地,在IDEA上配置Project SDK的路径

新建项目选址Spring Initializr, Project SDK选择本地安装的版本;

新建项目时根据提示填好参数;

组件依赖可以选择必要的jpa和redis及辅助插件lombok;

把配置文件改为yml文件

  1. server:
  2. port: 9999
  3. spring:
  4. profiles:
  5. active: dev

添加dev环境的配置文件

  1. server:
  2. servlet:
  3. context-path: /demo

去掉数据库的校验(暂时不需要使用数据库)

  1. package org.demo.springboot;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  5. import javax.sql.DataSource;
  6. @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
  7. public class SpringbootApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(SpringbootApplication.class, args);
  10. }
  11. }

添加restfull接口:

  1. /**
  2. * Copyright 2020 michelin.com.cn All right reserved. This software is the
  3. * confidential and proprietary information of michelin.com.cn ("Confidential
  4. * Information"). You shall not disclose such Confidential Information and shall
  5. * use it only in accordance with the terms of the license agreement you entered
  6. * into with michelin.com.cn.
  7. */
  8. package org.demo.springboot.order;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. /**
  16. * 描 述:class description.
  17. * <p>
  18. * Copyright: Copyright (c) 2020
  19. *
  20. * @author 葛东升
  21. * @version 1.0 6/29/21
  22. * @see HISTORY 6/29/21 葛东升 创建文件
  23. */
  24. @RestController
  25. @RequestMapping("/order")
  26. public class OrderController {
  27. @GetMapping("/queryAll")
  28. public List<HashMap<String,String>> queryAll(){
  29. List<HashMap<String, String>> res = new ArrayList<>();
  30. HashMap<String, String> r = new HashMap<>();
  31. r.put("1","hello");
  32. res.add(r);
  33. return res;
  34. }
  35. }

启动项目后在浏览器中验证接口

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/57664
推荐阅读
相关标签
  

闽ICP备14008679号