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

浙公网安备 33010602011771号