javascript
创建springboot_【小练习】创建SpringBoot程序
目錄
程序效果
配置文件修改
注解使用
參考資料
程序效果
截圖1.訪問URL顯示字符?
內置tomcat服務器默認使用8080端口,添加程序中配置的“/hello”后綴能訪問hello()方法。配置文件修改
pom.xml配置文件中添加org.springframework.boot依賴,會自動下載相關的jar包。<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.5.9.RELEASEversion>
parent>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
dependency>
dependencies>
注解使用
截圖2.程序目錄?
僅實現2個文件,Application.java文件啟動服務,Controller.java文件添加URL請求映射關系。@SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
@SpringBootApplication是Sprnig Boot項目的核心注解,目的是開啟自動配置。@RestController
@RequestMapping("/hello")
public class Controller {
@RequestMapping("")
public String hello() {
return "hello world";
}
}
@RestController聲明該類是一個控制器,@RequestMapping聲明映射關系匹配“/hello”,URL訪問“localhost:8080/hello”調用hello()返回字符串“hello world”。參考資料
1.使用eclipse創建Spring Boot項目 https://www.cnblogs.com/txsblog/p/8566416.html
總結
以上是生活随笔為你收集整理的创建springboot_【小练习】创建SpringBoot程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python语句first、*middl
- 下一篇: js 判断变量是否有值返回bool_有没