<.html>
<h1>Member Join</h1>
<form action="/lec17/memJoin" method="post">
ID : <input type="text" name="memId" ><br />
PW : <input type="password" name="memPw" ><br />
MAIL : <input type="text" name="memMail" ><br />
PHONE : <input type="text" name="memPhone1" size="5"> -
<input type="text" name="memPhone2" size="5"> -
<input type="text" name="memPhone3" size="5"><br />
<input type="submit" value="Join" >
<input type="reset" value="Cancel" >
</form>
<a href="/lec17/resources/html/login.html">LOGIN</a> <a href="/lec17/resources/html/index.html">MAIN</a>
<MemberController.java>
@Controller
//@RequestMapping("/member") // /lec17/member/memJoin : member가 겹쳐서 있을 때
public class MemberController {
// MemberService service = new MemberService();
// @Autowired
@Resource(name="memService")
MemberService service;
// @RequestMapping("/memJoin") //GET 방식일 경우
@RequestMapping(value="/memJoin", method=RequestMethod.POST)
// public String memJoin(Model model, HttpServletRequest request)
public String memJoin(Member member)
{
/* String memId = request.getParameter("memId");
String memPw = request.getParameter("memPw");
String memMail = request.getParameter("memMail");
String memPhone1 = request.getParameter("memPhone1");
String memPhone2 = request.getParameter("memPhone2");
String memPhone3 = request.getParameter("memPhone3");*/
service.memberRegister(member.getMemId(), member.getMemPw(), member.getMemMail(), member.getMemPhone1(),
member.getMemPhone2(), member.getMemPhone3());
/*
* model.addAttribute("memId", memId); model.addAttribute("memPw", memPw);
* model.addAttribute("memMail", memMail); model.addAttribute("memPhone",
* memPhone1 + " - " + memPhone2 + " - " + memPhone3);
*/
return "memJoinOk"; //.jsp
}
}
<memJoinOk.jsp>
<%-- ID : ${memId}<br />
PW : ${memPw}<br />
Mail : ${memMail} <br />
Phone : ${memPhone} <br /> --%>
<!-- 커멘드 객체를 이용한 방법 -->
<p>ID : ${member.memId}</p>
<p>PW : ${member.memPw}</p>
<p>Mail : ${member.memMail}</p>
<p>phone : ${member.memPhone1}-${member.memPhone2}-${member.memPhone3}</p>
<controller>
public String memJoin(@ModelAttribute("mem") Member member)
이렇게 설정하면 jsp에서 설정한 이름으로 불러올 수 있다.
<p>ID : ${mem.memId}</p>
<controller>
@ModelAttribute("serverTimef")
public String getServerTime(Locale locale)
{
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
return dateFormat.format(date);
}
함수위에 ModelAttribute 를 설정하면
언제든 사용가능
<p> ${serverTimef} </p>
PHONE : <input type="text" name="memPhone[0].memPhone1" size="5"> -
<input type="text" name="memPhone[0].memPhone2" size="5"> -
<input type="text" name="memPhone[0].memPhone3" size="5"><br />
.
.
.
<Member>
private List<MemPhone> memPhone;
<MemPhone>
private String memPhone1;
private String memPhone2;
private String memPhone3;
model 대신 ModelAndView 쓸 경우
@RequestMapping(value = "/memModify", method = RequestMethod.POST)
public ModelAndView memModify(Member member) {
Member[] members = service.memberModify(member);
ModelAndView mav = new ModelAndView();
mav.addObject("memBef", members[0]);
mav.addObject("memAft", members[1]);
mav.setViewName("memModifyOk");
return mav;
}
'Back-end > Spring Framework' 카테고리의 다른 글
java spring 리다이렉트, 인터셉트 (0) | 2020.08.12 |
---|---|
java spring 세션 & 쿠키 (0) | 2020.08.10 |
java spring , controller & dao & service 객체 (0) | 2020.08.08 |
java spring 스프링 mvc 웹서비스 STS(spring tools suite) (0) | 2020.08.06 |
java spring 스프링 MVC 플레임워크 설계 구조 (0) | 2020.08.04 |
댓글