728x90

PHP ( name="key_name[ ]" )

<! DOCTYPE html>
<html lang = "kr" >
<head>
<meta charset = "utf-8" >
<title> 키보드와 하루 </title>
</head>
<body>
<?php
    $v_keyname = $_POST [ "key_name" ];
    print_r( $v_keyname );

    //값이 있을 경우에는 체크박스에서 체크를 하기 위한 함수
    function check( $val , $array ) {
        if (in_array( $val , $array )) {
            echo "checked" ;
        }
    }
?>
<form method = "POST" action = "<?php echo $_SERVER [ 'PHP_SELF' ];?>" >
    <label>
    <input type = "checkbox" name = "key_name[]" value = "keyman1" <?php check( "keyman1" ,  $v_keyname );} ?> > 키 관리자1
    </label>
    <label>
    <input type = "checkbox" name = "key_name[]" value = "keyman2" <?php check( "keyman2" , $v_keyname );} ?> > 키 관리자2
    </label>
    
    <input type = "submit" value = "전송" />
</form>
</body>
</html>

 

Spring ( name="s_mu_del" )

<form name="requestForm" id="requestForm" method="post" action="/basic/auth_save"> 
    <table class="table table-sm  table-bordered table-hover" id="authTable">
        <colgroup>
            <col width="20%">
            <col width="20%"> 
        </colgroup>
        <thead class="thead-light">
            <tr>
                <th scope="col" class="text-center">1</th>
                <th scope="col" class="text-center">2</th> 
            </tr>
        </thead>
        <tbody> 
             </tr>    
                <td>
                    <input type="checkbox"  name="s_mu_del" value="${allMenuList.mm_code}" />
                </td> 
                <td>
                    <input type="checkbox"  name="s_mu_del" value="${allMenuList.mm_code}" />
                </td> 
             </tr> 
        </tbody>
    </table>
</form>


@PostMapping("/auth_save")
public String userAuthModify(HttpSession session ,  
	Model model,
	@RequestParam(value="s_mu_del[]") List<String> s_mu_del ) throws Exception{

    String mu_del = (s_mu_del == null) ? "N" : (s_mu_del.contains(code.getMm_code()) ? "Y" : "N");
    model.addAttribute("mu_del", mu_del);
    
    return "redirect:/basic/auth";
}

 

@RequestParam Map<String, Object> paramMap

<c:forEach var="list" items="${prdList}" varStatus="status"> 
    <div class="form-check col-3">
      <input type="hidden" id="prd_checked" name="prd_checked" value="" />
      <input class="form-check-input" type="checkbox" value="${list.prd_id}" name="prd_checkbox" id="prd_${list.prd_id}" style="margin-top: 4px;">
      <label class="form-check-label" for="${list.prd_id}">
        ${list.prd_nm}
      </label>
    </div>
 </c:forEach>
 
 
 $('#btnSaveInfo').click(function(){
		
    var prdCheckArr = [];     // 배열 초기화   
    $("input[name='prd_checkbox']:checked").each(function(index, item) { 
        prdCheckArr.push($(this).val()); 
    })
    $("#prd_checked").val(prdCheckArr);

    if( $("#user_id").val() == ""){
        alert("관리자를 선택하세요."); 
        return false;
    }

    if(confirm("저장하시겠습니까?")){
        $('#fr_account').ajaxForm({
            url: "<c:url value='/account/saveAdminAccountInfo.do'/>",
            type: "post",
            dataType:"json",
            success: function(result){
                //window.location.reload();
                refreshTree( tempNode, tempAuth, tempText, tempId );  // menu.jsp
            },
            error: function (XMLHttpRequest,status,error){
                console.log("error:"+error); 
            },
            beforeSend : function(xhr) { }
        }).submit();				
    }   

}) 

 
 
@RequestMapping(value="/account/saveAdminAccountInfo.do", method=RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> saveAdminAccountInfo( @RequestParam Map<String, Object> paramMap, ModelAndView mv, HttpServletRequest request ) throws Exception {

    JSONObject json = new JSONObject(); 
    paramMap = CommUtil.getSessionParam(paramMap, request); // 로그인 사용자의 정보를 map으로 받아온다.
    commonService.updateAdminUserInfo(paramMap);	//tn_user
    commonService.updateAdminOdgp(paramMap);		//tn_ogdp

    commonService.deleteAdminUserPrdAuth(paramMap); // tn_user_product_auth all delete

    for( String prd : ((String) paramMap.get("prd_checked")).split(",") ) {
        System.out.println(">> "+ prd);
        paramMap.put("prd_id",prd);
        commonService.insertAdminUserPrdAuth(paramMap); // tn_user_product_auth  
    } 

    return JSONResponseUtil.getJSONResponse(json);
}

 

 

 

728x90

+ Recent posts