본문 바로가기
ERP Project

뷰페이지 구성 에러 해결(1)

by kwh_coding 2023. 7. 28.

첫 번째로는 스프링 프레임워크만 사용하다가 다른 tool도 사용을 해보자는 취지로 spring boot를 처음으로 사용하게 되면서

jsp파일과 html파일을 두 개 다 사용해야 하는데 그때의 properties 설정에서 조금 애먹었다.

 

해결된 결론부터 적어보자면

server.port=10000

spring.output.ansi.enabled=always

spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:templates/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.view-names=thymeleaf/*

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

이렇게 properties를 설정해 주고 컨트롤러에서 경로를 적어줄 땐,

 

	@GetMapping("/test")
	public String test() {
		return "thymeleaf/test";
	}
	
	@GetMapping("/testjsp")
	public String index() {
		return "index";
	}

이렇게 적어주면 "/test" 는 html파일로 읽어주고, "/testjsp" 는 jsp로 알아서 읽어주게 된다. 

 

spring.thymeleaf.view-names=thymeleaf/*

을 넣어 html파일이 있는 경로로 보낼 것인지 jsp파일이 있는 경로로 보낼 것인지 판별할 수 있도록 해준다.

 

그리고 jsp파일은 legacy project처럼 src/main/webapp/WEB-INF/views/ 로 경로 설정을 해줘야 한다.

 

처음엔 return "thymeleaf/test"가 아닌 return "test" 로 적었다가 test.html이 아닌 test.jsp로 인식을 해서 문제가 생겼었는데

몇시간 동안 구글링 삽질을 한 결과 앞에 설정한 view-names까지 적은 thymeleaf/test 로 적어줘야 test.html로 인식이 된다는 것을 알아냈다...

'ERP Project' 카테고리의 다른 글

역할 분담  (0) 2023.09.20
뷰페이지 구성 에러 해결(2)  (0) 2023.07.28
뷰페이지 구성(2)  (0) 2023.07.28
뷰페이지 구성  (0) 2023.07.15
DB 세팅  (0) 2023.07.15