SpringBoot_Demo
零散知识点
SpringBoot里面的坐标都是spring-boot-starter-***
SpringBoot是整合框架的框架(相当于是全注解的开发,会发xml配置省略).导入一个spring-boot-starter-web它会默认导入spring、Tomcat等号.
一:pom.xml配置坐标
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.itheima.demo </groupId> <artifactId>springboot_demo</artifactId> <version>1.0-SNAPSHOT</version> <!--Spring Boot的父级依赖--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> </parent> <dependencies> <!--Spring Web项目起步依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
二:编写入口类
2.1:DemoApplication.java
@SpringBootApplication public class DemoApplication{ //入口类,用main方法启动项目 public static void main(String[] args){ SpringApplication.run(DemoApplication.class,args); } }
三:编写Controller层的代码(测试)
@RestController @RequestMapping("/hello") public class HelloController{ //使用Restful风格 @GetMapping("/sayHello') public String sayHello(){ return "Hello World !!!"; } }
四:启动DemoApplication.java
访问:localhost:8080/hello/sayHello
plication.java