- HttpServletRequest
쿼리스트링으로 직접 적어주자
위에거 다른방식으로 하는것 같다
- @RequestParam
package com.study.springboot;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@RequestMapping("/")
public @ResponseBody String root() {
return "Form데이터 전달받아 사용하기";
}
@RequestMapping("/test1")
public String test1(HttpServletRequest request, Model model) {
String id = request.getParameter("id");
String name = request.getParameter("name");
model.addAttribute("id", id);
model.addAttribute("name", name);
return "test1";
}
@RequestMapping("/test2")
public String test2(@RequestParam("id") String id,
@RequestParam("name") String name,
Model model) {
model.addAttribute("id",id);
model.addAttribute("name",name);
return "test2";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
out.print("#01 : Hello World");
%>
<br>
당신의 아이디는 ${id }입니다.
당신의 이름은 ${name }입니다.
</body>
</html>
'Spring > 이론' 카테고리의 다른 글
command객체// @PathVariable// form 데이터보내기//void == String + return 메서드이름//css파일은 static에 //html은 컨트롤러를 거치지 않고 바로 접근가능 (0) | 2023.07.19 |
---|---|
롬북설치 (0) | 2023.07.19 |
model/ ModelAndView (0) | 2023.07.18 |
static(정적자원) //jsp사용 (0) | 2023.07.18 |
@Component//@Value//@Autowired /@Qualifier/@SpringBootApplication /@Controller /@RequestMapping/@ResponseBody (0) | 2023.07.18 |