程序编码
java_@Controller
Controller 签名可以标注一个类方法用于渲染某个静态资源
1 | @Controller |
java_@RestController
这一个签名往往用来处理api请求,常常和各种Mapping合用(eg:@GetMapping(“/api/home”)
@RestController
public class HomeRestController {
@GetMapping("/api/home")
public Map<String, String> home() {
Map<String, String> response = new HashMap<>();
response.put("message", "Hello, World!");
return response; // This returns {"message":"Hello, World!"} as JSON
}
}