- [spring boot 2.1.7] profile 및 logback 설정 - [spring boot 2.1.7] thymelef 설정 - [spring boot 2.1.7] mybatis - mysql 5.7 연동 - [spring boot 2.1.7] hibernate - mysql 5.7 연동 설정
|
소스 : https://github.com/yamoe/spring-boot-example/tree/master/03.jsp/arti
* jsp 설정
- build.gradle 추가
dependencies {
...
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:9.0.24'
implementation 'javax.servlet:jstl:1.2'
}
- application-common.yml 설정 추가
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
- jsp 파일 작성
<src/main/webapp/WEB-INF/jsp/page.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>page</title>
</head>
<body>
<h1>Hello</h1>
<c:if test="${not empty fruit}" >
<div>${fruit}</div>
</c:if>
</body>
</html>
- controller 작성
<JspController.java>
package com.example.arti.jsp;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value = "jsp")
public class JspController {
@RequestMapping("/page1")
public String test() throws Exception {
return "page";
}
@RequestMapping("/page2")
public ModelAndView mav() throws Exception{
// page 이름
ModelAndView mv = new ModelAndView("page");
// 변수,값 설정
mv.addObject("fruit", "apple");
return mv;
}
@RequestMapping("/page3")
public String view(Model model) {
// 변수,값 설정
model.addAttribute("fruit", "banana");
return "page";
}
// 문자열 전달
@RequestMapping("/str")
public @ResponseBody String str() throws Exception {
return "str";
}
}
- 실행
- 참고:
https://hongku.tistory.com/116
'Java' 카테고리의 다른 글
[pinpoint 1.8.4] 설치 준비 - hbase 1.2.7 standalone (0) | 2019.09.01 |
---|---|
[spring boot 2.1.7] hibernate - mysql 5.7 연동 설정 (0) | 2019.08.30 |
[spring boot 2.1.7] mybatis - mysql 5.7 연동 (0) | 2019.08.29 |
[spring boot 2.1.7] thymelef 설정 (0) | 2019.08.29 |
[spring boot 2.1.7] profile 및 logback 설정 (0) | 2019.08.29 |
[spring boot 2.1.7] 개발 준비 (0) | 2019.08.29 |
OpenJDK 설치 (0) | 2019.08.08 |
CentOS 자바 설치 (0) | 2019.01.04 |