spring boot 微服务例子一

2021-07-03 14:05

阅读:493

标签:variable   plugin   conf   val   fir   tap   enc   mave   version   

package com.example.hello.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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;


@SpringBootApplication
@RestController
@RequestMapping(value="hello")
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);

}
@RequestMapping(value="/{firstName}/{lastName}",method = RequestMethod.GET)
public String hello(@PathVariable("firstName") String fName,@PathVariable("lastName") String lName){
return String.format("Hello zhukezhi :%s %s",fName,lName);

}

}

pom文件如下:使用idea的new---》spring initialr功能可以自动生成这个文件。


xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.example.Hello
demo
0.0.1-SNAPSHOT
jar

demo
Demo project for helloSpring Boot


org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE


UTF-8
UTF-8
1.8



org.springframework.boot
spring-boot-starter


org.springframework.boot
spring-boot-starter-test
test


org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-web




org.springframework.boot
spring-boot-maven-plugin




完成以后编译文件并使用内置的tomcat运行
http://localhost:8080/hello/julia/david/
返回字符串或者json串

spring boot 微服务例子一

标签:variable   plugin   conf   val   fir   tap   enc   mave   version   

原文地址:https://www.cnblogs.com/davidzhu/p/9622533.html


评论


亲,登录后才可以留言!