MiPlatform Spring mvc

MiPlatform 2019. 2. 26. 16:42


@Controller

public class EmpController {

@Resource(name="service")

private EmpService empService;

@RequestMapping("getlist")

public void getList(HttpServletResponse response) throws Exception {

List<Map<String, Object>> list = empService.getList();

if(list == null) {

System.out.println("데이터 조회 오류");

return;

}

VariableList vl = new VariableList();

DatasetList dl = new DatasetList();

Dataset ds = new Dataset("empList");

ds.addColumn("m_idx", ColumnInfo.COLUMN_TYPE_STRING, 256);

ds.addColumn("m_id", ColumnInfo.COLUMN_TYPE_STRING, 256);

ds.addColumn("m_pw", ColumnInfo.COLUMN_TYPE_STRING, 256);

ds.addColumn("m_name", ColumnInfo.COLUMN_TYPE_STRING, 256);

ds.addColumn("m_level", ColumnInfo.COLUMN_TYPE_STRING, 256);

Iterator<Map<String, Object>> it = list.iterator();

while(it.hasNext()) {

Map<String, Object> item = it.next();

int row_num = ds.appendRow();

ds.setColumn(row_num, "m_idx", item.get("m_idx").toString());

ds.setColumn(row_num, "m_id", item.get("m_id").toString());

ds.setColumn(row_num, "m_pw", item.get("m_pw").toString());

ds.setColumn(row_num, "m_name", item.get("m_name").toString());

ds.setColumn(row_num, "m_level", item.get("m_level").toString());

}

dl.add(ds);

PlatformResponse pRes = new PlatformResponse(response,PlatformRequest.XML,"UTF-8");

pRes.sendData(vl,dl);

}

@RequestMapping("addemp")

public void addEmp(HttpServletRequest request, HttpServletResponse response) throws Exception {

VariableList vl = new VariableList();

PlatformRequest pReq = new PlatformRequest(request,"UTF-8");

pReq.receiveData();

vl = pReq.getVariableList();

Map<String, Object> map = new HashMap<String, Object>();

map.put("m_idx", vl.getValueAsString("m_idx"));

map.put("m_id", vl.getValueAsString("m_id"));

map.put("m_pw", vl.getValueAsString("m_pw"));

map.put("m_name", vl.getValueAsString("m_name"));

map.put("m_level", vl.getValueAsString("m_level"));

int cnt = empService.addEmp(map);

if(cnt == 0) {

System.out.println("데이터 입력 오류");

return;

}

getList(response);

}

@RequestMapping("editemp")

public void editEmp(HttpServletRequest request) throws Exception {

DatasetList dList = new DatasetList();

PlatformRequest pReq = new PlatformRequest(request, "utf-8");

pReq.receiveData();

dList = pReq.getDatasetList();

Dataset ds =  dList.getDataset("editList");


Map<String, Object> map = new  HashMap<String, Object>();


int row_cnt = ds.getRowCount();

System.out.println(row_cnt);

for(int i=0; i<row_cnt;i++) {

map.put("m_idx", ds.getColumnAsString(i, "m_idx"));

map.put("m_id", ds.getColumnAsString(i, "m_id"));

map.put("m_pw", ds.getColumnAsString(i, "m_pw"));

map.put("m_name", ds.getColumnAsString(i, "m_name"));

map.put("m_level", ds.getColumnAsString(i, "m_level"));

//ds.getColumn(arg0, arg1)   자료형이 Variant,,,,, mybatis가 몰라,,,,,,,,,,,,, 파리피터를 못받는 오류 발생

empService.editEmp(map);

}

}



  @RequestMapping("deleteemp")

public void deleteEmp(HttpServletRequest request) throws Exception {

DatasetList dList = new DatasetList();

PlatformRequest pReq = new PlatformRequest(request, "utf-8");

pReq.receiveData();

dList = pReq.getDatasetList();

Dataset ds =  dList.getDataset("editList");

Map<String, Object> map = new  HashMap<String, Object>();


//map.put("m_idx", ds.getOrgBuffColumn(0, "m_idx").toString()); 삭제된 데이터 두 곳 두에서 찾을 수 있다.

map.put("m_idx", ds.getDeleteColumn(0, "m_idx").toString());

empService.delete(map);

}

}