日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot 入门教程(1)

發布時間:2024/4/13 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot 入门教程(1) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

前言

1、什么是springboot?

? ? 簡單的理解就是一個快速開發框架集合,大家都叫他快速開發腳手架。

2、springboot有什么特征?

? ? ?它遵循“習慣由于配置”原則,使用springboot只需要少量配置,我們大部分時候可以使用他的默認配置;

? ? 它可以讓我們搭建項目更快速,可無配置整合第三方框架;

? ? 完全不使用xml配置,只是用自動配置或是Java config

? ? 它內嵌了servelt容器(tomcat、jetty),應用可以用jar的方式運行

? ? 集成了應用運行狀態的監控

3、學習springboot需要什么知識儲備?

? ? java這個不用說了,哈哈

? ? maven這個必須會用啦

? ? spring 、spring MVC ? 這兩個是最基本的,這里的spring 必須是 4.x版本,因為springboot使用了spring4.x 的@Conditional注解。

? ? 想要學好它你還必須對設計模式有一定理解,還有core java中的 反射、注解、泛型 這些必不可少了,這部分有助于我們去理解源碼。

第一個springboot demo

? ?1、 新建一個maven工程,大家可以直接到spring官網上去新建一個,下載下來,或是自己建一個。我提倡手動。

? ? 2、引入springboot依賴

????????<parent>
?? ??? ?????<groupId>org.springframework.boot</groupId>
?? ??? ?????<artifactId>spring-boot-starter-parent</artifactId>
?? ??? ?????<version>1.4.5.RELEASE</version>
?? ?????</parent>

????????<dependency>
?? ??? ??? ?<groupId>org.springframework.boot</groupId>
?? ??? ??? ?<artifactId>spring-boot-starter-web</artifactId>
?? ??? ?</dependency>

完整的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.pxk</groupId> <artifactId>springbootdemo </artifactId> <version>0.0.1-SNAPSHOT</version> <!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.BUILD-SNAPSHOT</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!-- Add Spring repositories --> <!-- (you don't need this if you are using a .RELEASE version) --> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories> </project>

? ? 當然這是一個web工程,項目結構如下圖

?

Application.java

package com.pxk;import org.apache.log4j.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class Application {private static Logger logger = Logger.getLogger(Application.class);/*** Main Start*/public static void main(String[] args) {SpringApplication.run(Application.class, args);logger.info("============= SpringBoot Start Success =============");}}

HelloController1.java

package com.pxk;import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController1 {@RequestMapping("/") String home() { return "Hello World pxk!"; } @RequestMapping("/hello/{myName}") String index(@PathVariable String myName) { return "Hello "+myName+"!!!"; } }

然后直接run Application,springboot就會啟動內嵌的tomcat,默認是不帶項目名,且端口為8080

訪問http://localhost:8080/ 如下圖

訪問:http://localhost:8080/hello/springboot,使用的是spring MVC的mapping方式,生成rest風格的訪問路徑

轉載于:https://my.oschina.net/u/1791512/blog/1523533

總結

以上是生活随笔為你收集整理的springboot 入门教程(1)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。