zoukankan      html  css  js  c++  java
  • springBoot配置

    springBoot配置

    1、pom.xml配置

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
     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/xsd/maven-4.0.0.xsd">
     3   <modelVersion>4.0.0</modelVersion>
     4 
     5   <groupId>com.zkk</groupId>
     6   <artifactId>springBootStudy</artifactId>
     7   <version>0.0.1-SNAPSHOT</version>
     8   <packaging>jar</packaging>
     9 
    10   <name>springBootStudy</name>
    11   <url>http://maven.apache.org</url>
    12 
    13   <parent>
    14       <groupId>org.springframework.boot</groupId>
    15       <artifactId>spring-boot-starter-parent</artifactId>
    16       <version>1.5.6.RELEASE</version>
    17       <relativePath></relativePath>
    18   </parent>
    19   <properties>
    20     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    21   </properties>
    22     
    23     <repositories>
    24         <repository>
    25             <id>nexus-aliyun</id>
    26             <name>nexus_aliyun</name>
    27             <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    28         </repository>
    29     </repositories>
    30 
    31   <dependencies>
    32     <dependency>
    33       <groupId>junit</groupId>
    34       <artifactId>junit</artifactId>
    35       <scope>test</scope>
    36     </dependency>
    37     
    38     <dependency>
    39         <groupId>org.springframework.boot</groupId>
    40         <artifactId>spring-boot</artifactId>
    41     </dependency>
    42     <dependency>
    43       <groupId>org.springframework.boot</groupId>
    44       <artifactId>spring-boot-starter-web</artifactId>
    45     </dependency>
    46     
    47     <dependency>
    48       <groupId>org.springframework.boot</groupId>
    49       <artifactId>spring-boot-starter-test</artifactId>
    50     </dependency>
    51   
    52   </dependencies>
    53   
    54   <build>
    55       <plugins>
    56           <plugin>
    57                <groupId>org.springframework.boot</groupId>
    58               <artifactId>spring-boot-maven-plugin</artifactId>
    59           </plugin>
    60       </plugins>
    61   </build>
    62 </project>
    pom.xml

    2、Application.class代码编写

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

    3、application.yml

    1 spring:
    2  profiles:
    3   active: prod
    application.yml
    1 server:
    2  port: 8081
    3  context-path: /study
    application-prod.yml

    4、helloword例子

     1 package com.zkk.springBootStudy;
     2 
     3 import org.json.JSONException;
     4 import org.json.JSONObject;
     5 import org.springframework.beans.factory.annotation.Autowired;
     6 import org.springframework.beans.factory.annotation.Value;
     7 import org.springframework.web.bind.annotation.GetMapping;
     8 import org.springframework.web.bind.annotation.RequestMapping;
     9 import org.springframework.web.bind.annotation.RequestParam;
    10 import org.springframework.web.bind.annotation.RestController;
    11 
    12 import com.zkk.springBootStudy.model.ModelRes;
    13 
    14 @RestController
    15 public class HelloWorld {
    16 
    17 //    @RequestMapping(value ="/hello", method = RequestMethod.GET)
    18     @GetMapping(value="/hello")
    19     public String say(@RequestParam("id") String id){
    20         return "id:" + id;
    21     }
    22 }
    HelloWord

    5、客户端请求

    http://localhost:8081/study/hello?id="123"

  • 相关阅读:
    回顾[2007-09-03 12:58:03]
    关于知音[2007-08-17 20:56:06]
    今天晚上吃散伙饭[2007-06-18 00:24:36]
    上次所料不错[2007-06-13 15:44:47]
    今天真没劲[2007-06-10 17:50:25]
    关于昨晚的梦[2007-05-07 12:12:06]
    iOS 自定义键盘
    iOSQuart2D绘图之UIImage简单使用
    iOS 两种不同的图片无限轮播
    iOS 简单引导界面
  • 原文地址:https://www.cnblogs.com/zk753159/p/9610941.html
Copyright © 2011-2022 走看看