boardAjax 만들기 3 (Account Insert 작업)
http://daplus.net/javascript-jquery%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC-select%EC%97%90-%EC%98%B5%EC%85%98%EC%9D%84-%EC%B6%94%EA%B0%80-%ED%95%98%EC%8B%9C%EA%B2%A0%EC%8A%B5%EB%8B%88%EA%B9%8C/ - 참고
- AccountDTO.java
public class AccountDTO {
private int account_seq;
private String profit_cost;
private String big_group;
private String middle_group;
private String small_group;
private String detail_group;
private String comments;
private int transaction_money;
private String transaction_date;
private String writer;
private String reg_date;
public int getAccount_seq() {
return account_seq;
}
public void setAccount_seq(int account_seq) {
this.account_seq = account_seq;
}
public String getProfit_cost() {
return profit_cost;
}
public void setProfit_cost(String profit_cost) {
this.profit_cost = profit_cost;
}
public String getBig_group() {
return big_group;
}
public void setBig_group(String big_group) {
this.big_group = big_group;
}
public String getMiddle_group() {
return middle_group;
}
public void setMiddle_group(String middle_group) {
this.middle_group = middle_group;
}
public String getSmall_group() {
return small_group;
}
public void setSmall_group(String small_group) {
this.small_group = small_group;
}
public String getDetail_group() {
return detail_group;
}
public void setDetail_group(String detail_group) {
this.detail_group = detail_group;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public int getTransaction_money() {
return transaction_money;
}
public void setTransaction_money(int transaction_money) {
this.transaction_money = transaction_money;
}
public String getTransaction_date() {
return transaction_date;
}
public void setTransaction_date(String transaction_date) {
this.transaction_date = transaction_date;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getReg_date() {
return reg_date;
}
public void setReg_date(String reg_date) {
this.reg_date = reg_date;
}
}
- sql-mapper-config.xml - 등록하기
<typeAlias alias="accountDTO" type="com.lime.account.dto.AccountDTO"/>
- Common_SQL.xml
<!-- 코드 테이블 에서 셀렉트 박스 리스트 검색 -->
<select id="selectCombo" resultType="egovMap" parameterType="String">
SELECT
CODE,
COM_KOR
FROM CODE_MASTER
WHERE
CATEGORY = #{category}
AND
USE_YN ='Y'
</select>
<!-- insert ACCOUNT_TB 테이블 -->
<insert id="insertAccount" parameterType="AccountDTO">
insert into ACCOUNT_TB
(account_seq,profit_cost,big_group,middle_group,small_group,detail_group,
comments,transaction_money,transaction_date,writer,reg_date)
values
(ACCOUNT_SEQ.NEXTVAL,#{profit_cost},#{big_group},#{middle_group},#{small_group, jdbcType=VARCHAR},#{detail_group, jdbcType=VARCHAR},
#{comments},#{transaction_money},#{transaction_date},#{writer},SYSDATE)
</insert>
- CommonService.java
public interface CommonService {
/**
* select box 조회
* @param profit_cost
* @return 조회 값들(code,com_kor)
* @throws Exception
*/
public List<EgovMap> selectCombo(String profit_cost) throws Exception;
public List<EgovMap> selectAll() throws Exception;
}
- CommonDAO.java
@Repository("commonDAO")
public class CommonDAO extends EgovAbstractMapper{
public List<EgovMap> selectAll() throws EgovBizException{
return selectList("Common.selectAll");
}
/**
* select box 조회
* @param profit_cost
* @return 조회 값들(code,com_kor)
* @throws EgovBizException
*/
public List<EgovMap> selectCombo(String profit_cost) throws EgovBizException{
return selectList("Common.selectCombo", profit_cost);
}
}
- CommonServiceImpl.java
@Service("commonService")
public class CommonServiceImpl implements CommonService {
@Resource(name="commonDAO")
private CommonDAO commonDAO;
@Override
public List<EgovMap> selectAll() throws Exception {
return commonDAO.selectAll();
}
//select box 조회
@Override
public List<EgovMap> selectCombo(String profit_cost) throws Exception {
return commonDAO.selectCombo(profit_cost);
}
}
- AccountController.java
@Controller
public class AccountController {
@Resource(name = "jsonView")
private MappingJackson2JsonView jsonView;
@Resource(name="accountService")
private AccountService accountService;
@Resource(name="commonService")
private CommonService commonService;
/**
* account 목록 조회
* @param searchVO - 조회할 정보가 담긴 SampleDefaultVO
* @param model
* @return "egovSampleList"
* @exception Exception
*/
@RequestMapping(value = "/account/accountList.do")
public String selectSampleList(HttpServletRequest request, ModelMap model) throws Exception {
Map<String, Object> inOutMap = CommUtils.getFormParam(request);
model.put("inOutMap", inOutMap);
return "/account/accountList";
}
/**
* account 인서트 창 이동
* @param request
* @return /account/accountInsert.jsp
* @throws Exception
*/
@RequestMapping(value="/account/accountInsert.do")
public String accountInsert(HttpServletRequest request, ModelMap model) throws Exception{
//Map<String, Object> inOutMap = new HashMap<>();
//List<EgovMap> resultMap= commonService.selectAll();
//inOutMap.put("category", "A000000");
List<EgovMap> resultMap= commonService.selectCombo("A000000");
System.out.println(resultMap);
model.put("resultMap", resultMap);
return "/account/accountInsert";
}
/**
* 2번째 select box
* @param request
* @return 2번째 조회 값들(code,com_kor)
* @throws Exception
*/
@RequestMapping(value="/account/selectCombo.do")
@ResponseBody
public List<EgovMap> selectCombo(@RequestParam("profit_cost") String profit_cost) throws Exception{
System.out.println("/account/selectCombo.do");
System.out.println(profit_cost);
//Map<String, Object> inOutMap = CommUtils.getFormParam(request);
List<EgovMap> inOutMap = commonService.selectCombo(profit_cost);
System.out.println(inOutMap);
return inOutMap;
//return mav;
//return new ModelAndView(jsonView, inOutMap);
}
/**
* 3번째 select box
* @param big_group
* @return 3번째 조회 값들
* @throws Exception
*/
@RequestMapping(value="/account/selectCombo2.do")
@ResponseBody
public List<EgovMap> selectCombo2(@RequestParam("big_group") String big_group) throws Exception{
System.out.println("/account/selectCombo2.do");
List<EgovMap> inOutMap = commonService.selectCombo(big_group);
System.out.println(inOutMap);
return inOutMap;
}
/**
* 4번째 select box
* @param middle_group
* @return 4번째 조회 값들
* @throws Exception
*/
@RequestMapping(value="/account/selectCombo3.do")
@ResponseBody
public List<EgovMap> selectCombo3(@RequestParam("middle_group") String middle_group) throws Exception{
System.out.println("/account/selectCombo3.do");
List<EgovMap> inOutMap = commonService.selectCombo(middle_group);
System.out.println(inOutMap);
return inOutMap;
}
/**
* 5번째 select box
* @param small_group
* @return 5번째 조회 값들
* @throws Exception
*/
@RequestMapping(value="/account/selectCombo4.do")
@ResponseBody
public List<EgovMap> selectCombo4(@RequestParam("small_group") String small_group) throws Exception{
System.out.println("/account/selectCombo4.do");
List<EgovMap> inOutMap = commonService.selectCombo(small_group);
System.out.println(inOutMap);
return inOutMap;
}
/**
* ACCOUNT_TB 테이블에 실제 insert 작업
* @param dto
* @return /account/accountList.jsp
* @throws Exception
*/
@RequestMapping(value="/account/accountInsertPro.do")
public ModelAndView accountInsertPro(AccountDTO dto) throws Exception {
accountService.insertAccount(dto);
ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/account/accountList.do");
return mav;
}
}// end of calss
- accountInsert.jsp
<form action="./accountInsertPro.do" name="myForm" method="post">
<div class="container" style="margin-top: 50px">
<div class="col-sm-12"><label for="disabledInput" class="col-sm-12 control-label"></label></div>
<div class="col-sm-12"><label for="disabledInput" class="col-sm-12 control-label"></label></div>
<div class="col-sm-12"><label for="disabledInput" class="col-sm-12 control-label"></label></div>
<div class="col-sm-12"><label for="disabledInput" class="col-sm-12 control-label"></label></div>
<div class="col-sm-11" id="costDiv">
<div>
<div class="col-sm-11">
<div class="col-sm-12">
<div class="col-sm-3">
<select class="form-control" id="profit_cost" name="profit_cost" title="비용">
<option value="">선택</option>
<c:forEach var="list" items="${resultMap}" varStatus="status">
<option value="${list.code}">${list.comKor}</option>
</c:forEach>
</select>
</div>
<div class="col-sm-3">
<select class="form-control" id="big_group" name="big_group" title="관" >
<option value="">선택</option>
<%--
<c:forEach var="list" items="${inOutMap}" varStatus="cnt">
<option value="${list.code}">${list.comKor}</option>
</c:forEach>
--%>
</select>
</div>
<div class="col-sm-3">
<select class="form-control " id="middle_group" name="middle_group" title="항">
<option value="0">해당없음</option>
</select>
</div>
<div class="col-sm-3">
<select class="form-control " id="small_group" name="small_group" title="목">
<option value="0">해당없음</option>
</select>
</div>
</div>
<div class="col-sm-12"> <label class="col-sm-12 control-label"> </label></div>
<div class="col-sm-12">
<div class="col-sm-3">
<select class="form-control " id="detail_group" name="detail_group" title="과">
<option value="0">해당없음</option>
</select>
</div>
<div class="col-sm-9">
<input class="form-control " name="comments" type="text" value="" placeholder="비용 상세 입력" title="비용 상세">
</div>
</div>
<div class="col-sm-12"> <label class="col-sm-12 control-label"> </label></div>
<div class="col-sm-12">
<label class="col-sm-1 control-label"><font size="1px">금액</font></label>
<div class="col-sm-3">
<input class="form-control" name="transaction_money" type="number" value="" title="금액">
</div>
<label class="col-sm-1 control-label"><font size="1px">거래일자</font></label>
<div class="col-sm-3">
<input class="datepicker" name="transaction_date" type="text" value="" style="width: 80%" title="거래일자">
</div>
</div>
<input type="hidden" name="writer" value="${sessionScope.userSession.user_id}">
<div class="col-sm-12" align="center">
<button type="submit" class="btn btn-primary">등록</button>
<button type="button" class="btn btn-danger">취소</button>
</div>
<label class="col-sm-12 control-label"></label>
</div>
</div>
</div>
</div>
</form>
<script>
$(document).ready(function(){
$("#profit_cost").change(function(){
var profit_cost = $(this).val();
start1(profit_cost);
f = document.myForm;
f.profit_cost.value = profit_cost;
});
});
function start1(profit_cost) {
$("#big_group").children('option').remove();
$.ajax({
url:'./selectCombo.do',
type:'POST',
data:{profit_cost : profit_cost},
success:function(result){
console.log(result);
//$('#bigGroup').html(result);
/*
$('#bigGroup').each(function(result) {
$('#bigGroup').append('<option value="' + result.com + '">' + result.comKor + '</option>');
});
*/
for(var i=0; i<result.length;i++){
$('#big_group').append('<option value=' + result[i].code + '>' + result[i].comKor + '</option>');
}
$("#big_group").change(function(){
var big_group = $(this).val();
console.log(big_group);
start2(big_group);
f = document.myForm;
f.big_group.value = big_group;
});
}
});
}
function start2(big_group) {
$("#middle_group").children('option').remove();
$.ajax({
url:'./selectCombo2.do',
type:'POST',
data:{big_group : big_group},
success:function(result){
console.log(result);
for(var i=0; i<result.length;i++){
$('#middle_group').append('<option value=' + result[i].code + '>' + result[i].comKor + '</option>');
}
$("#middle_group").change(function(){
var middle_group = $(this).val();
start3(middle_group);
f = document.myForm;
f.middle_group.value = middle_group;
});
}
});
}
function start3(middle_group) {
$("#small_group").children('option').remove();
$.ajax({
url:'./selectCombo3.do',
type:'POST',
data:{middle_group : middle_group},
success:function(result){
console.log(result);
for(var i=0; i<result.length;i++){
$('#small_group').append('<option value=' + result[i].code + '>' + result[i].comKor + '</option>');
}
$("#small_group").change(function(){
var small_group = $(this).val();
start4(small_group);
f = document.myForm;
f.small_group.value = small_group;
});
}
});
}
function start4(small_group) {
$("#detail_group").children('option').remove();
$.ajax({
url:'./selectCombo4.do',
type:'POST',
data:{small_group : small_group},
success:function(result){
console.log(result);
for(var i=0; i<result.length;i++){
$('#detail_group').append('<option value=' + result[i].code + '>' + result[i].comKor + '</option>');
}
$("#detail_group").change(function(){
var detail_group = $(this).val();
//start4(detail_group);
f = document.myForm;
f.detail_group.value = detail_group;
});
}
});
}
</script>
'교육 정리 > 입사교육' 카테고리의 다른 글
boardAjax 만들기 5 (리스트 페이징2, 엑셀파일 다운로드) (0) | 2021.08.13 |
---|---|
boardAjax 만들기 4 (수정, 리스트 페이징) (0) | 2021.08.12 |
boardAjax 만들기 2 (로그인 구현, 경로수정) (0) | 2021.08.10 |
mavenBoard 만들기 6 (오류 수정), boardAjax 만들기(환경 설정,회원가입 구현) (0) | 2021.08.09 |
mavenBoard 만들기 5 (파일 게시판 만들기2) (0) | 2021.08.08 |
댓글