CommandMap에 HttpServletRequest 사전 탑재
This commit is contained in:
@@ -90,25 +90,7 @@ 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")
|
||||
public ModelAndView openBoardWrite(CommandMap commandMap) throws Exception
|
||||
@@ -118,34 +100,13 @@ public class BoardController
|
||||
System.out.println("========JRebel Test============");
|
||||
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")
|
||||
public ModelAndView insertBoard(CommandMap commandMap, HttpServletRequest request) throws Exception
|
||||
public ModelAndView insertBoard(CommandMap commandMap) throws Exception
|
||||
{
|
||||
ModelAndView mv = new ModelAndView("redirect:/sample/openBoardList.do");
|
||||
|
||||
boardService.insertBoard(commandMap.getMap(), request);
|
||||
boardService.insertBoard(commandMap.getMap(), commandMap.getRequest());
|
||||
|
||||
return mv;
|
||||
}
|
||||
@@ -177,11 +138,11 @@ public class BoardController
|
||||
}
|
||||
|
||||
@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");
|
||||
|
||||
boardService.updateBoard(commandMap.getMap(), request);
|
||||
boardService.updateBoard(commandMap.getMap(), commandMap.getRequest());
|
||||
|
||||
mv.addObject("IDX", commandMap.get("IDX"));
|
||||
return mv;
|
||||
|
||||
@@ -4,10 +4,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
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){
|
||||
return map.get(key);
|
||||
}
|
||||
@@ -51,4 +54,15 @@ public class CommandMap {
|
||||
public Map<String,Object> getMap(){
|
||||
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로 캐스팅
|
||||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
|
||||
//Request의 HttpServletRequest 헤더(파일 업로드 관련) 내장
|
||||
commandMap.setRequest(request);
|
||||
|
||||
Enumeration<?> enumeration = request.getParameterNames();
|
||||
|
||||
String key;
|
||||
@@ -45,6 +48,9 @@ public class CustomMapArgumentResolver implements HandlerMethodArgumentResolver
|
||||
commandMap.put(key, (values.length > 1) ? values : values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return commandMap;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user