zoukankan      html  css  js  c++  java
  • java Sprint boot 学习之一

      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.3.6.RELEASE</spring.version>
        <springboot.version>1.5.1.RELEASE</springboot.version>
      </properties>
    
    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
          <version>${springboot.version}</version>
    
        </dependency>
      </dependencies>
      <build>
        <plugins>
    
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
    
        
    
        </plugins>
      </build>

    主函数

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Properties;
    import java.util.Stack;
    
    /**
     * HelloController world!
     *
     */
    @SpringBootApplication
    public class App 
    {
        public static void main( String[] args )
        {
            SpringApplication.run(App.class,args);
    
        }
    }

    3.Controller

    package com.ppmoney.g2;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.xml.ws.Action;
    
    /**
     *
     */
    @RestController
    public class HelloController {
        //@GetMapping("/app/hello/{name}")
        @RequestMapping(value = "/app/hello", method = RequestMethod.GET)
        public String hello0( String name)
        {
            return "Hello "+name;
        }
    
        @RequestMapping(value = "/app/hello/{name}", method = RequestMethod.GET)
        public String hello1(@PathVariable String name)
        {
            return "Hello1 "+name;
        }
    
        @RequestMapping(value = "/app/hello2/{name}", method = RequestMethod.GET)
        public String hello2(HttpServletResponse response,@PathVariable String name)
        {
            response.setStatus(404);
            return "Hello2 "+name;
        }
    }

    4.application.properties

    ##服务器HTTP端口
    server.port=9080

    5.调用

    http://localhost:9080/app/hello?name=sdfasd

    http://localhost:9080/app/hello/stss

    http://localhost:9080/app/hello2/stss

  • 相关阅读:
    js将手机号中间四位变成*
    js判断浏览器客户端类型
    vue项目涉及到的setInterval
    MYSQL 总结——2
    MySQL补充
    PyCharm软件安装
    MYSQL 总结——1
    linux系统通过ssh拉取gitee项目 设置权限
    tp5开源的后台管理系统
    window下Python安装
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/6636315.html
Copyright © 2011-2022 走看看