springframework

spring学习笔记

1
2
3
4
5
6
7
8
9
10
11
12
@RestController
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
//这个地方最想说的是俩个东西: format 和 atomicLong ,线程安全
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}

spring项目启动的方法

  • 两种方法

    1. 直接运行:

      ./mvnw spring-boot:run  //直接运行的就是该springboot 项
      
    2. jar包运行 :

      ./mvnw clean package//打包成jar包
      java -jar target / gs-rest-service-0.1.0.jar//运行该包