Editor with Spring

Editor with Spring

sngsu_blue-bizsngsu_blue-biz Posts: 1Questions: 1Answers: 0

Hi,
English isn't my first language, so please excuse any mistake. and also i'm new to developing, so please excuse my lack of knowledge. i'm trying to keep up.
I could not find any post about using Editor in Spring. I hope someone can help me.
The problem is, I can get the data from DB but could not create/edit/delete and those buttons don't show up.

Here is what error says:
DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Here is a picture of table.

if you need anything, please let me know.
Thank you.

------script--------------------------------------------------------------

var editor; 

    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            table: "#example",
            idSrc:  'comp_cd',
            fields: [ {
                label: "cust_cd:",
                name: "cust_cd"
            }, {
                label: "comp_cd:",
                name: "comp_cd"
            }
            ]
        } );

        // Activate an inline edit on click of a table cell
        $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
            editor.inline( this );
        } );

        $.ajax({

            type: "post"
            , url: "<c:url value='/mes/base/company/compPage' />"
            , headers: {
                "Content-Type": "application/json"
                , "X-HTTP-Method-Override": "POST"
            }
            , data: JSON.stringify({
                cust_cd: $("#cust_cd").val()
                , keywords: $("#keywords").val()
                , comp_type: $("#comp_type").val()
                , comp_group: $("#comp_group").val()
                , comp_yn: $("input[name=comp_yn]:checked").val()
            })
            , dataType: "json"
            , success: function (data) {
                $('#example').DataTable( {
                    dom: "Bfrtip",
                    // data: data,
                    data: data,
                    order: [[ 1, 'asc' ]],
                    columns: [
                        {
                            data: null,
                            defaultContent: '',
                            className: 'select-checkbox',
                            orderable: false
                        },
                        { data: "cust_cd" },
                        { data: "comp_cd" },
                    ],
                    select: {
                        style:    'os',
                        selector: 'td:first-child'
                    },
                    buttons: [
                        { extend: "create", editor: editor },
                        { extend: "edit",   editor: editor },
                        { extend: "remove", editor: editor }
                    ],
                    ajax: {
                        create: '/mes/base/company/compPage', // default method is POST
                        edit: {
                            type: 'PUT',
                            url:  '/mes/base/company/compPage'
                        },
                        remove: {
                            type: 'DELETE',
                            url:  '/mes/base/company/compPage'
                        }
                    }
                } );
            }
        });
    } );

-----RestController-------------------------------------------------

@RequestMapping(value = "/mes/base/company/compPage", method = RequestMethod.POST)
    public ResponseEntity<List<Map<String, Object>>> compPagePOST(VMap vmap, @RequestBody Map<String, Object> map) {
        ResponseEntity<List<Map<String, Object>>> entity = null;
        try {
            vmap.set(map);
            vmap.put("columnList", userService.searchColumn("COL_COMP"));

            List<Map<String, Object>> list = companyService.compPage(vmap);
            entity = new ResponseEntity<>(list, HttpStatus.OK);
        } catch (Exception e) {
            e.printStackTrace();
            entity = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
        return entity;
    }

-------Service--------------------------------------

public <T> List<T> compPage(VMap vmap) throws Exception {
        return companyDAO.compPage(vmap.getMap());
    }

------mapper--------------------------------

<mapper namespace="mes.base.company">

<select id="compPage" parameterType="vmap" resultType="rmap">
        SELECT 
            CUST_CD
            ,COMP_CD
            , COMP_CD AS DT_ROWID
        FROM BS_COMP_INFO BCI
        WHERE CUST_CD = #{cust_cd}
</select>

---------table-----------------------------------

CREATE TABLE `bs_comp_info` (
  `CUST_CD` varchar(6) NOT NULL COMMENT '고객코드',
  `COMP_CD` varchar(20) NOT NULL COMMENT '거래처코드',
  `COMP_NO` varchar(20) NOT NULL COMMENT '거래처번호',
  `COMP_NM` varchar(50) NOT NULL COMMENT '거래처명',
  `COMP_TYPE` varchar(2) NOT NULL COMMENT '구분 (고객사:C / 협력사:V)',
  `COMP_GROUP` varchar(20) DEFAULT NULL COMMENT '분류',
  `COMP_IDNUM` varchar(12) DEFAULT NULL COMMENT '등록번호',
  `COMP_CEO` varchar(12) DEFAULT NULL COMMENT '대표자명',
  `COMP_COND` varchar(50) DEFAULT NULL COMMENT '업태',
  `COMP_KIND` varchar(50) DEFAULT NULL COMMENT '종목',
  `COMP_TEL` varchar(15) DEFAULT NULL COMMENT '대표전화',
  `COMP_FAX` varchar(15) DEFAULT NULL COMMENT 'FAX',
  `COMP_ADDR` varchar(100) DEFAULT NULL COMMENT '주소',
  `COMP_ADMIN` varchar(12) DEFAULT NULL COMMENT '담당자',
  `COMP_MOBILE` varchar(15) DEFAULT NULL COMMENT '담당자 연락처',
  `COMP_EMAIL` varchar(50) DEFAULT NULL COMMENT '담당자 이메일',
  `COMP_YN` char(1) NOT NULL DEFAULT 'Y' COMMENT '거래여부',
  `COMP_NT` varchar(100) DEFAULT NULL COMMENT '비고',
  `COMP_CRDT` datetime NOT NULL COMMENT '등록일시',
  `COMP_UPDT` datetime NOT NULL COMMENT '수정일시',
  `COMP_SABN` varchar(12) NOT NULL COMMENT '등록수정자',
  PRIMARY KEY (`CUST_CD`,`COMP_CD`),
  CONSTRAINT `FK_DF_CUST_INFO_TO_BS_COMP_INFO` FOREIGN KEY (`CUST_CD`) REFERENCES `df_cust_info` (`CUST_CD`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='거래처정보'

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    The first thing to do would to follow the diagnostic steps in the URL given in that error message. Have you tried that? If so, please can you report back on your findings.

    Colin

This discussion has been closed.