首先,在 http://start.spring.io 配置并下载一个最简单的web工程,并且导入我们的IDE,我选择的是Intellij IDEA。
工程结构如上图所示:
紧接着在com.example包下创建一个HelloController ,代码如下:
package com.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by Joe on 2017/3/1.
*/
@RestController
public class HelloController {
protected static Logger logger= LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String helloworld(){
logger.info("访问hello");
return "Hello world!";
}
@RequestMapping("/hello/{name}")
public String helloName(@PathV