入门程序

  1. 创建表现层的package文件web,由于启动类的注解@SpringBootApplication内嵌了包扫描注解,因此,需要与启动在同一级目录下,否则在表现层使用注解会无效
    SpringBoot入门程序
  2. 编写表现层代码
package com.cax.SpringBootDemo.web;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class HelloController {

    @RequestMapping(value = "/say")
    public String say(){
        return "Hello SpringBoot";
    }
}

  1. 运行结果
    SpringBoot入门程序

PS:

  1. 关于@Controller和@RestController的区别

前者是用于返回视图,需要配置试图解析器;后者是@Controller和@ResponseBody的结合,用于返回字符串或者json格式的数据。

相关文章:

  • 2021-08-06
  • 2021-07-14
  • 2021-05-26
  • 2021-05-07
  • 2021-10-23
  • 2022-12-23
  • 2021-10-06
  • 2021-08-14
猜你喜欢
  • 2021-12-23
  • 2021-11-13
  • 2022-01-14
  • 2021-12-12
  • 2021-07-14
  • 2021-08-07
  • 2022-12-23
相关资源
相似解决方案