1.SpringBoot项目基本运行

首先Controller类 使用注解@RestController

注:

@RestController 含义:@Controller + @ResponseBody:(https://www.jianshu.com/p/6bbb5748ac83)

@RestController = @Controller + @ResponseBody组成,等号右边两位同志简单介绍两句,就明白我们@RestController的意义了:

  • @Controller 将当前修饰的类注入SpringBoot IOC容器,使得从该类所在的项目跑起来的过程中,这个类就被实例化。当然也有语义化的作用,即代表该类是充当Controller的作用
  • @ResponseBody 它的作用简短截说就是指该类中所有的API接口返回的数据,甭管你对应的方法返回Map或是其他Object,它会以Json字符串的形式返回给客户端,本人尝试了一下,如果返回的是String类型,则仍然是String。

 

Application类 放置到项目包的最外面,默认格式如下,因为SpringBoot默认集成tomcat,所以直接运行Application就可以启动项目

@SpringBootApplication
public class Application {

   public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
   }
}

 

maven配置(pom.xml)



   4.0.0
   com.demo
   projectName
   1.0
   jar
   
      org.springframework.boot
      spring-boot-starter-parent
      2.1.1.RELEASE
   
   
      UTF-8
      1.8
   
   
      
         org.springframework.boot
         spring-boot-starter-web
      
      
         org.springframework.boot
         spring-boot-starter-test
      
   
   
      
         
            org.springframework.boot
            spring-boot-maven-plugin
         
      
   

 

 

冷姿势

resource目录下,存储SpringBoot下任意命名banner的txt文件 jpg图片都可以在项目启动的时候展示出来

你可能感兴趣的:(SpringBoot)