zoukankan      html  css  js  c++  java
  • spring-boot入门

    Eclipse中安装STS插件

    (1)在线安装

      Help--Eclipse Marketplace

      搜索“STS”,点击“install”安装

      

      后面就是一直下一步或者完成

    (2)离线安装

      打开网页 http://spring.io/tools/sts/all

      下载适合自己的eclipse版本的STS压缩包

      

      下载后,在eclipse操作: Help--Install New Software--Add--Archive,添加已下载的zip包

      

      安装有Spring IDE字样的插件即可,取消勾选自动更新,接下来就有Next就点Next,有Finish就点Finish

      

    2. 创建Spring-boot项目

      新建->其它

      

      我这里没啥要改的,默认demo就行

      

      下面其他第三方库可以一个都不加入,可以在使用的时候再pom里面再次添加,如果知道需要哪些也可以提前勾上

      

       完成

    3. 运行Spring-boot项目

    (1)右键DemoApplication中的main方法,Run As -> Spring Boot App,项目就可以启动了

     1 package com.example.demo;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.SpringBootApplication;
     5 
     6 @SpringBootApplication
     7 public class DemoApplication {
     8 
     9     public static void main(String[] args) {
    10         SpringApplication.run(DemoApplication.class, args);
    11     }
    12 }

    (2)如果要运行hello world,则使用@RestController注解,并且添加hello方法

       得提前引入web相关的依赖,如果之前勾选了,就不用再加了

      

    1         <dependency>
    2             <groupId>org.springframework.boot</groupId>
    3             <artifactId>spring-boot-starter-web</artifactId>
    4         </dependency>
     1 package com.example.demo;
     2 
     3 import org.springframework.boot.SpringApplication;
     4 import org.springframework.boot.autoconfigure.SpringBootApplication;
     5 import org.springframework.web.bind.annotation.RequestMapping; 
     6 import org.springframework.web.bind.annotation.RestController; 
     7   
     8 @RestController
     9 @SpringBootApplication
    10 public class DemoApplication {
    11     
    12     @RequestMapping("/") 
    13     public String hello(){ 
    14          return"Hello world!"; 
    15      } 
    16     public static void main(String[] args) {
    17         SpringApplication.run(DemoApplication.class, args);
    18     }
    19 }

      

      如何运行我们的Application,看到hello world的输出呢?

      第一种方式是直接运行main方法:

      选中DemoApplication的main方法 -> 右键 -> Run as ->Java Applicacation,之后打开浏览器输入地址:http://127.0.0.1:8080/ 或者http://localhost:8080/就可以看到Hello world!了。

      第二种方式:

      右键project –> Run as –> Maven build –> 在Goals里输入spring-boot:run ,然后Apply,最后点击Run

    4. 打包Spring-boot项目

    1.命令:clean package

      

    2.执行命令:java –jar xxxxxx.jar

  • 相关阅读:
    javaScript
    alsa驱动分析(1)
    Android 音频系统[相当好zz]
    verilog语法学习心得[zz]
    Linux ALSA声卡驱动之二:声卡的创建[zz]
    关于手机线控耳机那点事儿!![zz]
    armlinux备忘
    聊聊Android的音频架构[zz]
    片上系统(SOC)设计流程及其集成开发环境[zz]
    记录中心设置
  • 原文地址:https://www.cnblogs.com/zhuimengdeyuanyuan/p/7942570.html
Copyright © 2011-2022 走看看