//관리자 추가 @RequestMapping(value="/admin", method=RequestMethod.POST) public String addManager( Manager manager,HttpServletRequest req,Model model){ Account account=new Account(); account.setId(manager.getId()); account.setPassword(manager.getPassword()); try{ accountService.save(account, "ROLE_MANAGER", "MANAGER"); managerMapper.insertManager(manager); }catch(Exception ex){ ex.printStackTrace(); model.addAttribute("message","관리자 추가 에러!!"); return "admin/admin"; } model.addAttribute("message","정상적으로 추가되었습니다"); return "admin/admin"; }
<div class="container"> <div class="row" style="padding-top:10%"> <div class="col-md-4 "></div> <div class="col-md-4 border border-light rounded " style="flex-align:center"> <form style="margin:10px" method="post" action="/admin"> <div class="form-group"> <label for="InputId">아이디</label> <input type="text" class="form-control" id="id" name="id" placeholder="ID"> </div> <div class="form-group"> <label for="InputPassword">비밀번호</label> <input type="password" class="form-control" id="password" name="password" placeholder="Password"> </div> <div class="form-group"> <label for="InputName">이름</label> <input type="text" class="form-control" id="name" name="name" placeholder="Name"> </div> <div class="form-group"> <label for="InputCenterId">센터아이디</label> <input type="text" class="form-control" id="centerId" name="centerId" placeholder="Center ID"> </div> <div class="form-group"> <label for="phoneNumber">휴대폰 번호</label> <input type="text" class="form-control" id="phoneNumber" name="phoneNumber" placeholder="PhoneNumber"> </div> <button type="submit" class="btn btn-block btn-primary text-light">서비스 이용자 등록</button> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" /> </form> </div>
컨트롤러에서 Manager 타입의 객체로 폼값을 한번에 받아오는 코드인데,
사실 어려울 것도 없는데 자꾸 sql 에러나는거 ㅠㅠ
알고보니 내가 폼에 name이 아닌 id로 일치시켜줬던거 ,,
잊지말자 매핑은 name으로!