DataTables Cannot read property 'length' of undefined 이라는 에러.
기본적으로 ajax 에서 받아오는 데이터를 화면 (JSP) 에 뿌릴 때 데이터 수와 테이블 수가 달라서 안나오는 경우가 많다.
하지만 이번에 나온 경우는 BackEnd 에서 ajax 로 넘길 값을 서비스impl 에서 담지 않고 보내서 나는 에러였다.
package kr.co.smartix.service.impl;
import kr.co.smartix.common.domain.PageResource;
import kr.co.smartix.domain.company.CompanyVO;
import kr.co.smartix.domain.member.MemberVO;
import kr.co.smartix.domain.member.MyAuthenticaion;
import kr.co.smartix.domain.reservation.ReserveVO;
import kr.co.smartix.mapper.CompanyMapper;
import kr.co.smartix.mapper.ReserveMapper;
import kr.co.smartix.service.CompanyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.List;
@Service
@Validated
@Slf4j
@RequiredArgsConstructor //어노테이션의 특성을 사용하면 @Autowired나 @Resource @Inject 어노테이션 없이 DI 주입이 가능합니다
@Transactional( propagation= Propagation.REQUIRED, readOnly=true)
public class CompanyServiceImpl implements CompanyService {
private final CompanyMapper companyMapper;
private final PageResource resource = new PageResource();
@Override
public PageResource selectCompanyList(MemberVO memberVO) {
MemberVO memberOutputVO = ((MyAuthenticaion) SecurityContextHolder.getContext().getAuthentication()).getMemberVO();
String upidkey = memberOutputVO.getUpidkey();
String idgubun = memberOutputVO.getIdgubun();
String name = memberOutputVO.getName();
String insertDt = memberOutputVO.getInsertDt();
String email = memberOutputVO.getEmail();
String pwd = memberOutputVO.getPwd();
String tel = memberOutputVO.getTel();
String useYn = memberOutputVO.getUseYn();
String id = memberOutputVO.getIdkey();
/*memberVO.setName(name);*/
memberVO.setIdkey(id);
memberVO.setIdkey(upidkey);
memberVO.setIdgubun(idgubun);
/* memberVO.setName(name);
memberVO.setInsertDt(insertDt);
memberVO.setEmail(email);
memberVO.setPwd(pwd);
memberVO.setTel(tel);
memberVO.setUseYn(useYn);*/
//long total = companyMapper.selectCompanyCnt(memberVO);
//memberVO.getPageHelper().setTotalCount(total);
List<MemberVO> companyList = companyMapper.selectCompanyList(memberVO);
resource.setData(companyList);
resource.setRecordsTotal(11);
resource.setRecordsFiltered(11);
resource.setLength(memberVO.getPageHelper().getLinePerPage());
resource.setStart(memberVO.getPageHelper().getStartRow());
return resource;
}
}
resource.setData(companyList); <= 이렇게 담아서 넘겨줬어야했는데 못했다...
휴...멍청..