ㅗㅜㅑ
This commit is contained in:
@@ -17,22 +17,23 @@ public class TodoDao implements TodoService{
|
||||
ResultSet rs;
|
||||
|
||||
|
||||
final String SELECT_ALL = "SELECT * FROM userTodo";
|
||||
final String SELECT_ALL = "SELECT * FROM userTodo where userno = ?";
|
||||
@Override
|
||||
public ArrayList<TodoVo> selectAll(Connection conn){
|
||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo){
|
||||
ArrayList<TodoVo> list = new ArrayList<TodoVo>();
|
||||
try{
|
||||
psmt = conn.prepareStatement(SELECT_ALL);
|
||||
psmt.setInt(1, userNo);
|
||||
rs = psmt.executeQuery();
|
||||
|
||||
|
||||
while(rs.next()){
|
||||
TodoVo vo = new TodoVo();
|
||||
vo.setuNo(rs.getInt("uNo"));
|
||||
vo.setUserno(rs.getInt("userno"));
|
||||
vo.setuContent(rs.getString("uContent"));
|
||||
vo.setuDay(rs.getString("uDay"));
|
||||
vo.setuNpc(rs.getString("uNpc"));
|
||||
vo.setuCheck(rs.getString("uCheck"));
|
||||
vo.setuSub1(rs.getString("uSub1"));
|
||||
vo.setuSub2(rs.getString("uSub2"));
|
||||
list.add(vo);
|
||||
}
|
||||
}catch(SQLException throwables){
|
||||
@@ -47,9 +48,26 @@ public class TodoDao implements TodoService{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final String UPDATE = "UPDATE userTodo SET uContent = ?, uCheck = ?, uSub1 = ?, uSub2 = ? WHERE uNo = ?";
|
||||
@Override
|
||||
public int update(Connection conn, TodoVo vo){
|
||||
return 0;
|
||||
int result = 0;
|
||||
try{
|
||||
psmt = conn.prepareStatement(UPDATE);
|
||||
psmt.setString(1, vo.getuContent());
|
||||
psmt.setString(2, vo.getuCheck());
|
||||
psmt.setString(3, vo.getuSub1());
|
||||
psmt.setString(4, vo.getuSub2());
|
||||
psmt.setInt(5, vo.getuNo());
|
||||
|
||||
|
||||
result = psmt.executeUpdate();
|
||||
}catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface TodoService{
|
||||
public ArrayList<TodoVo> selectAll(Connection conn);
|
||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo);
|
||||
public int insert(Connection conn, TodoVo vo);
|
||||
public int update(Connection conn, TodoVo vo);
|
||||
public int delete(Connection conn, TodoVo vo);
|
||||
|
||||
@@ -18,8 +18,8 @@ public class TodoServiceImpl implements TodoService{
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<TodoVo> selectAll(Connection conn){
|
||||
return todoDao.selectAll(conn);
|
||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo){
|
||||
return todoDao.selectAll(conn, userNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,8 @@ public class TodoVo{
|
||||
String uDay;
|
||||
String uNpc;
|
||||
String uCheck;
|
||||
String uSub1;
|
||||
String uSub2;
|
||||
|
||||
public int getuNo(){
|
||||
return uNo;
|
||||
@@ -55,4 +57,20 @@ public class TodoVo{
|
||||
public void setuCheck(String uCheck){
|
||||
this.uCheck = uCheck;
|
||||
}
|
||||
|
||||
public String getuSub1(){
|
||||
return uSub1;
|
||||
}
|
||||
|
||||
public void setuSub1(String uSub1){
|
||||
this.uSub1 = uSub1;
|
||||
}
|
||||
|
||||
public String getuSub2(){
|
||||
return uSub2;
|
||||
}
|
||||
|
||||
public void setuSub2(String uSub2){
|
||||
this.uSub2 = uSub2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -20,6 +23,7 @@ import java.util.List;
|
||||
@Controller
|
||||
public class TodoController{
|
||||
|
||||
|
||||
TodoService todoService;
|
||||
|
||||
@Autowired
|
||||
@@ -30,14 +34,68 @@ public class TodoController{
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/getTodoData.do")
|
||||
public HashMap<String, Object> getTodoData(Model model){
|
||||
public HashMap<String, Object> getTodoData(HttpServletRequest request, Model model){
|
||||
HttpSession session = request.getSession();
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
Connection conn = Dao.getConnection();
|
||||
ArrayList<TodoVo> list = todoService.selectAll(conn);
|
||||
int userNo = (int)session.getAttribute("userNo");
|
||||
ArrayList<TodoVo> list = todoService.selectAll(conn, userNo);
|
||||
HashMap<Integer, Integer> boardMap = new HashMap<Integer, Integer>();
|
||||
int index = 1;
|
||||
for(TodoVo vo : list){
|
||||
boardMap.put(index, vo.getuNo());
|
||||
vo.setuNo(index);
|
||||
++index;
|
||||
}
|
||||
|
||||
session.setAttribute("todoMap", boardMap);
|
||||
|
||||
Dao.close(conn);
|
||||
|
||||
map.put("list", list);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/todoUpdate.do")
|
||||
public HashMap<String, Object> todoUpdate(HttpServletRequest request,
|
||||
@RequestBody HashMap<String, Object> map,
|
||||
Model model){
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
HttpSession session =request.getSession();
|
||||
HashMap<Integer, Integer> boardMap = (HashMap<Integer, Integer>)session.getAttribute("todoMap");
|
||||
int todoNo = Integer.parseInt((String)map.get("todoNo"));
|
||||
String content = (String)map.get("content");
|
||||
String check = (String)map.get("check");
|
||||
Object o1 = map.get("sub1");
|
||||
Object o2 = map.get("sub2");
|
||||
String sub1 = null;
|
||||
String sub2 = null;
|
||||
if( o1 != null){
|
||||
sub1= o1.toString();
|
||||
}
|
||||
if( o2 != null){
|
||||
sub2= o2.toString();
|
||||
}
|
||||
|
||||
Connection conn = Dao.getConnection();
|
||||
if(!(check.equals("true") || check.equals("false")))
|
||||
{
|
||||
returnMap.put("result", 0);
|
||||
}else{
|
||||
TodoVo vo = new TodoVo();
|
||||
vo.setuNo(boardMap.get(todoNo));
|
||||
vo.setuCheck(check);
|
||||
vo.setuContent(content);
|
||||
vo.setuSub1(sub1);
|
||||
vo.setuSub2(sub2);
|
||||
|
||||
int result = todoService.update(conn, vo);
|
||||
returnMap.put("result", result);
|
||||
}
|
||||
Dao.close(conn);
|
||||
return returnMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user