CommandMap에 HttpServletRequest 사전 탑재
This commit is contained in:
@@ -91,24 +91,6 @@ public class BoardController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/sample/testMapArgumentResolver.do")
|
|
||||||
public ModelAndView testMapArgumentResolver(CommandMap commandMap) throws Exception
|
|
||||||
{
|
|
||||||
ModelAndView mv = new ModelAndView("");
|
|
||||||
|
|
||||||
if(commandMap.isEmpty() == false)
|
|
||||||
{
|
|
||||||
Iterator<Entry<String,Object>> iterator = commandMap.getMap().entrySet().iterator();
|
|
||||||
Entry<String,Object> entry = null;
|
|
||||||
while(iterator.hasNext())
|
|
||||||
{
|
|
||||||
entry = iterator.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value="/sample/openBoardWrite.do")
|
@RequestMapping(value="/sample/openBoardWrite.do")
|
||||||
public ModelAndView openBoardWrite(CommandMap commandMap) throws Exception
|
public ModelAndView openBoardWrite(CommandMap commandMap) throws Exception
|
||||||
@@ -119,33 +101,12 @@ public class BoardController
|
|||||||
return mv;
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/sample/Test.do")
|
|
||||||
public ModelAndView Test(CommandMap commandMap) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
ModelAndView mv = new ModelAndView("/sample/Test"); //JSP 파일 지정
|
|
||||||
System.out.println("========Test Test============");
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value="/sample/kk.do")
|
|
||||||
public ModelAndView kk(CommandMap commandMap) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
ModelAndView mv = new ModelAndView("/sample/kk"); //JSP 파일 지정
|
|
||||||
System.out.println("========kk Test============");
|
|
||||||
return mv;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value="/sample/insertBoard.do")
|
@RequestMapping(value="/sample/insertBoard.do")
|
||||||
public ModelAndView insertBoard(CommandMap commandMap, HttpServletRequest request) throws Exception
|
public ModelAndView insertBoard(CommandMap commandMap) throws Exception
|
||||||
{
|
{
|
||||||
ModelAndView mv = new ModelAndView("redirect:/sample/openBoardList.do");
|
ModelAndView mv = new ModelAndView("redirect:/sample/openBoardList.do");
|
||||||
|
|
||||||
boardService.insertBoard(commandMap.getMap(), request);
|
boardService.insertBoard(commandMap.getMap(), commandMap.getRequest());
|
||||||
|
|
||||||
return mv;
|
return mv;
|
||||||
}
|
}
|
||||||
@@ -177,11 +138,11 @@ public class BoardController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/sample/updateBoard.do") //수정하기 누르는~~ 혹은 저장하기 누르는~~
|
@RequestMapping(value="/sample/updateBoard.do") //수정하기 누르는~~ 혹은 저장하기 누르는~~
|
||||||
public ModelAndView updateBoard(CommandMap commandMap, HttpServletRequest request) throws Exception
|
public ModelAndView updateBoard(CommandMap commandMap) throws Exception
|
||||||
{
|
{
|
||||||
ModelAndView mv = new ModelAndView("redirect:/sample/openBoardDetail.do");
|
ModelAndView mv = new ModelAndView("redirect:/sample/openBoardDetail.do");
|
||||||
|
|
||||||
boardService.updateBoard(commandMap.getMap(), request);
|
boardService.updateBoard(commandMap.getMap(), commandMap.getRequest());
|
||||||
|
|
||||||
mv.addObject("IDX", commandMap.get("IDX"));
|
mv.addObject("IDX", commandMap.get("IDX"));
|
||||||
return mv;
|
return mv;
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class CommandMap {
|
public class CommandMap {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
private Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
private HttpServletRequest request = null;
|
||||||
|
|
||||||
public Object get(String key){
|
public Object get(String key){
|
||||||
return map.get(key);
|
return map.get(key);
|
||||||
@@ -51,4 +54,15 @@ public class CommandMap {
|
|||||||
public Map<String,Object> getMap(){
|
public Map<String,Object> getMap(){
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpServletRequest getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequest (HttpServletRequest _request) {
|
||||||
|
request = _request;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,9 @@ public class CustomMapArgumentResolver implements HandlerMethodArgumentResolver
|
|||||||
|
|
||||||
// 🚨 최신 Jakarta EE 스펙의 HttpServletRequest로 캐스팅
|
// 🚨 최신 Jakarta EE 스펙의 HttpServletRequest로 캐스팅
|
||||||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
|
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
|
||||||
|
//Request의 HttpServletRequest 헤더(파일 업로드 관련) 내장
|
||||||
|
commandMap.setRequest(request);
|
||||||
|
|
||||||
Enumeration<?> enumeration = request.getParameterNames();
|
Enumeration<?> enumeration = request.getParameterNames();
|
||||||
|
|
||||||
String key;
|
String key;
|
||||||
@@ -45,6 +48,9 @@ public class CustomMapArgumentResolver implements HandlerMethodArgumentResolver
|
|||||||
commandMap.put(key, (values.length > 1) ? values : values[0]);
|
commandMap.put(key, (values.length > 1) ? values : values[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return commandMap;
|
return commandMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user