Spring/spring_old

spring boot basic

slow333 2023. 5. 12. 11:05

start.spring.io => 프로젝트 생성 => 압축 해제 => intellij에서 불러옴

(web, thymeleaf implement)

java version이 11로 되어 있어서 애러남 -> setting => gradle 설정에서 17로 변경

project setting에서 17로 변경 , 모두 통일 하면 애러 없음

기본으로 8080 포트를 열음

 

기본 Home page는 resources/static/intex.html 을 불러옴(localhost:8080 => 실행)

 

controller 구성

project/controller/NameController.java 를 생성

@Controller
public class HelloController {

List<String> list = new ArrayList<>(Arrays.asList("2343", "Arrays.asList","added"));


@GetMapping("olleh") // url 경로를 나타냄, restfull api
public String hello(Model model){ // 모델을 입력 받아서 스트링을 돌려 줌
  list.add("ok added");
  model.addAttribute("data", list);
// key, value mapping
return "hello"; // templates/hello return ...
}

}

index.html, resources/templates/hello.html 생성

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<title>index html</title>
</head>
<body>

<a href="/olleh">hello go there(/olleh)</a>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>

<p th:text = "'안녕하세요 ' + ${data}"> hello index for test</p>

</body>
</html>

'Spring > spring_old' 카테고리의 다른 글

11. JPA 사용을 위한 코딩  (0) 2023.01.27
10. JPA 구현을 위한 환경 구성  (0) 2023.01.26
09. DB 연계-JPA  (0) 2023.01.26
08. MVC Controller 생성  (4) 2023.01.26
05. Spring Cloud Config  (0) 2023.01.25