SpringBoot 入門 Demo

來源:互聯網
上載者:User

標籤:連接埠   jstl   pack   嵌入   代碼   demo   title   檔案中   develop   

SpringBoot   入門 Demo

 

Spring Boot是由Pivotal團隊提供的全新架構,其設計目的是用來簡化新Spring應用的初始搭建以及開發過程。該架構使用了特定的方式來進行配置,從而使開發人員不再需要定義樣板化的配置。通過這種方式,Spring Boot致力於在蓬勃發展的快速應用開發領域(rapid application development)成為領導者。

 

特點  1. 建立獨立的Spring應用程式  2. 嵌入的Tomcat,無需部署WAR檔案  3. 簡化Maven配置  4. 自動設定Spring  5. 提供生產就緒型功能,如指標,健全狀態檢查和外部配置  6. 絕對沒有代碼產生和對XML沒有要求配置

springBoot 簡介地址:

  https://baike.baidu.com/item/Spring%20Boot/20249767?fr=aladdin#1

 

1.學習SpringBoot 需要有 ssm 的基礎知識 

2. SpringBoot 是在Maven 環境下開發的 需要有Maven 知識做鋪墊

3.開發工具  (IDEA  , eclipse  )

4. 實際開發步驟:

  1.) 建立一個   maven  工程

  2.) Maven  是 Web 專案

  3.) 完善maven 建立的目錄結構

  

    

  4.) 修改   pom.xml   檔案

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3   <modelVersion>4.0.0</modelVersion> 4   <groupId>dt55</groupId> 5   <artifactId>springboot1</artifactId> 6   <packaging>war</packaging> 7   <version>0.0.1-SNAPSHOT</version> 8   <name>springboot1 Maven Webapp</name> 9   <url>http://maven.apache.org</url>10      11      <!-- 配置spring boot所需的依賴 -->12     <parent>13         <groupId>org.springframework.boot</groupId>14         <artifactId>spring-boot-starter-parent</artifactId>15         <version>1.5.10.RELEASE</version>16     </parent>17     18     <dependencies>19         <!-- spring boot的相關啟動 -->20         <dependency>21             <groupId>org.springframework.boot</groupId>22             <artifactId>spring-boot-starter-web</artifactId>23         </dependency>24         25         <!-- 熱部署 -->26         <dependency>27             <groupId>org.springframework.boot</groupId>28             <artifactId>spring-boot-devtools</artifactId>29             <optional>true</optional>30             <scope>true</scope>31         </dependency>32         33         <!-- log4j -->34         <dependency>35             <groupId>org.springframework.boot</groupId>36             <artifactId>spring-boot-starter-log4j2</artifactId>37         </dependency>38         39         <!-- 使用Jasper引擎解析JSP -->40         <dependency>41             <groupId>org.apache.tomcat.embed</groupId>42             <artifactId>tomcat-embed-jasper</artifactId>43             <scope>provided</scope>44         </dependency>45         46         <!--jsp支援-->47         <!-- servlet 依賴. -->48         <dependency>49           <groupId>javax.servlet</groupId>50           <artifactId>javax.servlet-api</artifactId>51           <scope>provided</scope>52         </dependency>53         <dependency>54           <groupId>javax.servlet</groupId>55           <artifactId>jstl</artifactId>56         </dependency>57         58         <!-- spring boot整合mybatis -->59         <dependency>60             <groupId>org.mybatis.spring.boot</groupId>61             <artifactId>mybatis-spring-boot-starter</artifactId>62             <version>1.3.0</version>63         </dependency>64 65         <!-- MySQL -->66         <dependency>67             <groupId>mysql</groupId>68             <artifactId>mysql-connector-java</artifactId>69         </dependency>70      71   </dependencies>72   73   <build>74       <plugins>75             <plugin>76                 <groupId>org.springframework.boot</groupId>77                 <artifactId>spring-boot-maven-plugin</artifactId>78                 <configuration>79                     <!-- 沒有該配置,devtools 不生效 -->80                     <fork>true</fork>81                 </configuration>82             </plugin>83         </plugins>84     <finalName>springboot1</finalName>85   </build>86 </project>

   5.) 修改連接埠號碼 建立一個 application.properties 檔案

             1 server.port=8888 

   6.) 配置資料來源資訊  在application.properties 檔案中配置資料來源

     

1 spring.datasource.driver-class-name=com.mysql.jdbc.Driver2 spring.datasource.url=jdbc:mysql:///dt553 spring.datasource.username=root4 spring.datasource.password=root

 

 7.) 測試代碼:

 1 /** 2  * Project Name:springboot1 3  * File Name:FrontController.java 4  * Package Name:cn.java.controller.front 5  * Date:下午5:21:57 6  * Copyright (c) 2018, bluemobi All Rights Reserved. 7  * 8 */ 9 10 package cn.java.controller.front;11 12 import java.util.List;13 import java.util.Map;14 15 import org.mybatis.spring.annotation.MapperScan;16 import org.springframework.beans.factory.annotation.Autowired;17 import org.springframework.boot.SpringApplication;18 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;19 import org.springframework.context.annotation.ComponentScan;20 import org.springframework.stereotype.Controller;21 import org.springframework.web.bind.annotation.RequestMapping;22 import org.springframework.web.bind.annotation.ResponseBody;23 24 import cn.java.service.FrontService;25 26 /**27  * Description: <br/>28  * Date: 下午5:21:57 <br/>29  * 30  * @author 朱開心31  * @version32  * @see33  */34 @Controller35 @EnableAutoConfiguration36 @ComponentScan(value = { "cn.java.controller.*", "cn.java.service.impl" })37 @MapperScan(value = "cn.java.mapper")38 public class FrontController {39 40     @Autowired41     private FrontService frontService;42 43     @RequestMapping("/index")44     @ResponseBody45     public String getLogin() {46         return "Hello World !!!!!";47     }48 49     public static void main(String[] args) {50         // 啟動springboot架構51         SpringApplication.run(FrontController.class, args);52     }53 54 }

 

  

 就是這麼的簡單的操作 ,比 ssm  簡單的多啦  

道友們試試吧  有問題 @我

  

SpringBoot 入門 Demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.