zoukankan      html  css  js  c++  java
  • idea实现第一个springboot程序

    1.环境准备

    • JDK:1.8
    • Apache Maven: 3.6.1
    • IntelliJ IDEA 2019.1.3 x64
    • SpringBoot 1.5.9.RELEASE:1.5.9;

    1.1、MAVEN设置:给maven 的settings.xml配置文件的profiles标签添加

    <profile>
      <id>jdk-1.8</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
    

    2.实现SpringBoot Helloworld 案例

    浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串;

    2.1、创建一个maven工程;(jar)

    2.2、导入spring boot相关的依赖

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.RELEASE</version>
        </parent>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    

    3、编写一个主程序;启动Spring Boot应用

    
    package com.xdr;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    /*
    @SpringBootApplication 来标注一个主程序
     */
    @SpringBootApplication
    public class HelloWorldApplication {
        public static void main(String[] args) {
            System.out.println("启动springboot程序");
            SpringApplication.run(HelloWorldApplication.class, args);
        }
    }
    
    

    4、编写相关的Controller、Service

    package com.xdr.com.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class Controller {
        @RequestMapping("hello")
        public String sayHello(){
            return "Hello SpringBoot";
        }
    }
    
    
    

    5、运行主程序测试

    在resource下创建application.properties文件写入

    server.port=8082
    

    把端口号改为8082,以免跟8080冲突
    在这里插入图片描述
    访问项目
    在这里插入图片描述

    6、简化部署

     <!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    

    将这个应用打成jar包,直接使用java -jar xxx.jar(xxx表示jar包的名称)的命令进行执行;
    在idea自带Maven打包中
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    刷新项目:
    在这里插入图片描述

  • 相关阅读:
    页面跳转刷新
    表格表头绘制对角线(不固定表格宽高)
    发送邮件的工具类
    重写equals()和hashCode()
    设计模式--原型模式[转载]
    设计模式--外观模式
    设计模式--代理模式
    js处理json js递归
    MySQL锁详解
    开发一个微信小程序实例教程
  • 原文地址:https://www.cnblogs.com/xdr630/p/15255177.html
Copyright © 2011-2022 走看看