Controller

@Controller←アノテーションつければok

public class MainController {}
(JSONXML などを返す WebAPI 用の Controller などには@RestControllerを使う)

@RequestMapping("/")は万能らしい?(一般的には特定のURLリクエストに対してマッピング)

@GetMappingと@PostMappingはGetとPost専用になる

 

public ModelAndView index(ModelAndView mav) {

mav.setViewName("index");←ファイル名指定

int a = 50, b = 100;

int ans = a + b;

mav.addObject("ans", ans);←ansという名前に変数ansを登録。th:text=${ans}で取れる

return mav;

}