zoukankan      html  css  js  c++  java
  • springboot 框架

    功能:浏览器发送hello请求,服务器接收请求并处理,返回hello word字符串

    一、创建一个maven项目

    二、在pom.xml文件中添加依赖导入springboot框架运行需要的依赖

     1     <!-- 继承了一个父项目 -->
     2     <parent>
     3         <groupId>org.springframework.boot</groupId>
     4         <artifactId>spring-boot-starter-parent</artifactId>
     5         <version>2.2.4.RELEASE</version>
     6         <relativePath/> <!-- lookup parent from repository -->
     7     </parent>
     8 
     9     <dependencies>
    10         <!-- web模块的依赖 -->
    11     <dependency>
    12                  <groupId>org.springframework.boot</groupId>
    13                  <artifactId>spring-boot-starter-web</artifactId>
    14         </dependency>
    15     </dependencies>

    三、编写一个主程序,自动Springboot

    具体启动代码如下:

     1 /**
     2  * @SpringBootApplication 主程序类的标注
     3  */
     4 @SpringBootApplication
     5 public class HelloWordMainApplication {
     6     //main方法快捷键是 psvm
     7     public static void main(String[] args) {
     8         //spring boot 应用启动起来,
     9         SpringApplication.run(HelloWordMainApplication.class,args);
    10     }
    11 }

    四、编写相关的controller,service

    • 新建一个controller类

         

    • 具体代码如下  
      1 @Controller
      2 public class HelloController {
      3 
      4     @ResponseBody  //把接口返回的结果写在浏览器上
      5     @RequestMapping("/hello") //接收来自浏览器的hello请求
      6     public String hello(){
      7         return "Hello Word";
      8     }
      9 }
                                       

    五、启动main程序,在浏览器中打开http://localhost:8080/hello 测试结果,结果返回如下

  • 相关阅读:
    makefile中宏定义
    make的静态模式
    makefile中两重if判断
    定义命令包
    嵌套执行make
    AcWing 1014. 登山
    AcWing 482. 合唱队形
    AcWing 1027. 方格取数
    AcWing 1016. 最大上升子序列和
    AcWing 187. 导弹防御系统
  • 原文地址:https://www.cnblogs.com/mysummary/p/12236908.html
Copyright © 2011-2022 走看看