할일 추가 기능
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -131,6 +131,13 @@
|
|||||||
<version>2.10.3</version>
|
<version>2.10.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-dbcp2</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package co.nook.app.common;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
public class Dao{
|
|
||||||
|
|
||||||
public static Connection getConnection(){
|
|
||||||
Connection conn = null;
|
|
||||||
try{
|
|
||||||
Class.forName("org.mariadb.jdbc.Driver");
|
|
||||||
|
|
||||||
String url = "jdbc:mariadb://coon.myds.me:3307/NookSearch";
|
|
||||||
String userId = "minechost";
|
|
||||||
String pw = "Ahstmxj5zos1!";
|
|
||||||
conn = DriverManager.getConnection(url, userId, pw);
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void close(Connection conn){
|
|
||||||
try{
|
|
||||||
conn.close();
|
|
||||||
}catch(SQLException throwables){
|
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
package co.nook.app.todo.dao;
|
package co.nook.app.todo.dao;
|
||||||
|
|
||||||
|
import co.nook.app.todo.service.TodoMapper;
|
||||||
import co.nook.app.todo.service.TodoService;
|
import co.nook.app.todo.service.TodoService;
|
||||||
import co.nook.app.todo.vo.TodoVo;
|
import co.nook.app.todo.vo.TodoVo;
|
||||||
|
import co.nook.app.user.service.UserMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -13,65 +18,64 @@ import java.util.ArrayList;
|
|||||||
@Repository("todoDao")
|
@Repository("todoDao")
|
||||||
public class TodoDao implements TodoService{
|
public class TodoDao implements TodoService{
|
||||||
|
|
||||||
PreparedStatement psmt;
|
JdbcTemplate jdbcTemplate;
|
||||||
ResultSet rs;
|
|
||||||
|
@Autowired
|
||||||
|
public TodoDao(JdbcTemplate jdbcTemplate){
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final String SELECT_ALL = "SELECT * FROM userTodo where userno = ?";
|
final String SELECT_ALL = "SELECT * FROM userTodo where userno = ?";
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo){
|
public ArrayList<TodoVo> selectAll(int userNo){
|
||||||
ArrayList<TodoVo> list = new ArrayList<TodoVo>();
|
return (ArrayList<TodoVo>)jdbcTemplate.query(SELECT_ALL, new TodoMapper(), userNo);
|
||||||
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.setuContent(rs.getString("uContent"));
|
|
||||||
vo.setuCheck(rs.getString("uCheck"));
|
|
||||||
vo.setuSub1(rs.getString("uSub1"));
|
|
||||||
vo.setuSub2(rs.getString("uSub2"));
|
|
||||||
list.add(vo);
|
|
||||||
}
|
}
|
||||||
}catch(SQLException throwables){
|
final String SELECT_LAST = "SELECT * FROM userTodo where uNo = LASTVAL(seq_user_todo)";
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(Connection conn, TodoVo vo){
|
public TodoVo selectLast() throws SQLException{
|
||||||
return 0;
|
try {
|
||||||
|
return jdbcTemplate.queryForObject(SELECT_LAST, new TodoMapper() );
|
||||||
|
} catch (EmptyResultDataAccessException e) {
|
||||||
|
// EmptyResultDataAccessException 예외 발생시 null 리턴
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String INSERT = "INSERT INTO userTodo (uNo, userno, uContent, uCheck, uSub1, uSub2) " +
|
||||||
|
"values (NEXTVAL(seq_user_todo), ?, ?, ?, 0, ?)";
|
||||||
|
@Override
|
||||||
|
public int insert(TodoVo vo){
|
||||||
|
int n = jdbcTemplate.update(INSERT,
|
||||||
|
vo.getUserno(),
|
||||||
|
vo.getuContent(),
|
||||||
|
vo.getuCheck(),
|
||||||
|
vo.getuSub2()
|
||||||
|
);
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String UPDATE = "UPDATE userTodo SET uContent = ?, uCheck = ?, uSub1 = ?, uSub2 = ? WHERE uNo = ?";
|
final String UPDATE = "UPDATE userTodo SET uContent = ?, uCheck = ?, uSub1 = ?, uSub2 = ? WHERE uNo = ?";
|
||||||
@Override
|
@Override
|
||||||
public int update(Connection conn, TodoVo vo){
|
public int update( TodoVo vo){
|
||||||
int result = 0;
|
System.out.println("변경 Userno : "+vo.getuNo());
|
||||||
try{
|
System.out.println("변경 Contetn : " +vo.getuContent());
|
||||||
psmt = conn.prepareStatement(UPDATE);
|
int n = jdbcTemplate.update(UPDATE,
|
||||||
psmt.setString(1, vo.getuContent());
|
vo.getuContent(),
|
||||||
psmt.setString(2, vo.getuCheck());
|
vo.getuCheck(),
|
||||||
psmt.setString(3, vo.getuSub1());
|
vo.getuSub1(),
|
||||||
psmt.setString(4, vo.getuSub2());
|
vo.getuSub2(),
|
||||||
psmt.setInt(5, vo.getuNo());
|
vo.getuNo()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
result = psmt.executeUpdate();
|
System.out.println("변경 : " +n);
|
||||||
}catch(SQLException e){
|
return n;
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Connection conn, TodoVo vo){
|
public int delete( TodoVo vo){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/main/java/co/nook/app/todo/service/TodoMapper.java
Normal file
22
src/main/java/co/nook/app/todo/service/TodoMapper.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package co.nook.app.todo.service;
|
||||||
|
|
||||||
|
import co.nook.app.todo.vo.TodoVo;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class TodoMapper implements RowMapper<TodoVo>{
|
||||||
|
@Override
|
||||||
|
public TodoVo mapRow(ResultSet rs, int rowNum) throws SQLException{
|
||||||
|
TodoVo vo = new TodoVo();
|
||||||
|
vo.setuNo(rs.getInt("uNo"));
|
||||||
|
vo.setUserno(rs.getInt("userno"));
|
||||||
|
vo.setuContent(rs.getString("uContent"));
|
||||||
|
vo.setuCheck(rs.getString("uCheck"));
|
||||||
|
vo.setuSub1(rs.getString("uSub1"));
|
||||||
|
vo.setuSub2(rs.getString("uSub2"));
|
||||||
|
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,13 @@ package co.nook.app.todo.service;
|
|||||||
import co.nook.app.todo.vo.TodoVo;
|
import co.nook.app.todo.vo.TodoVo;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface TodoService{
|
public interface TodoService{
|
||||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo);
|
public ArrayList<TodoVo> selectAll( int userNo ) throws SQLException;
|
||||||
public int insert(Connection conn, TodoVo vo);
|
public TodoVo selectLast() throws SQLException;
|
||||||
public int update(Connection conn, TodoVo vo);
|
public int insert( TodoVo vo ) throws SQLException;
|
||||||
public int delete(Connection conn, TodoVo vo);
|
public int update( TodoVo vo ) throws SQLException;
|
||||||
|
public int delete( TodoVo vo ) throws SQLException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Service("todoService")
|
@Service("todoService")
|
||||||
@@ -18,22 +19,27 @@ public class TodoServiceImpl implements TodoService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<TodoVo> selectAll(Connection conn, int userNo){
|
public ArrayList<TodoVo> selectAll( int userNo){
|
||||||
return todoDao.selectAll(conn, userNo);
|
return todoDao.selectAll( userNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(Connection conn, TodoVo vo){
|
public TodoVo selectLast() throws SQLException{
|
||||||
return todoDao.insert(conn, vo);
|
return todoDao.selectLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Connection conn, TodoVo vo){
|
public int insert( TodoVo vo) {
|
||||||
return todoDao.update(conn, vo);
|
return todoDao.insert( vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Connection conn, TodoVo vo){
|
public int update(TodoVo vo){
|
||||||
return todoDao.delete(conn, vo);
|
return todoDao.update( vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int delete( TodoVo vo){
|
||||||
|
return todoDao.delete( vo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package co.nook.app.todo.web;
|
package co.nook.app.todo.web;
|
||||||
|
|
||||||
import co.nook.app.common.Dao;
|
|
||||||
import co.nook.app.todo.dao.TodoDao;
|
|
||||||
import co.nook.app.todo.service.TodoService;
|
import co.nook.app.todo.service.TodoService;
|
||||||
import co.nook.app.todo.vo.TodoVo;
|
import co.nook.app.todo.vo.TodoVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -10,15 +8,14 @@ import org.springframework.ui.Model;
|
|||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class TodoController{
|
public class TodoController{
|
||||||
@@ -34,13 +31,12 @@ public class TodoController{
|
|||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping(value = "/getTodoData.do")
|
@RequestMapping(value = "/getTodoData.do")
|
||||||
public HashMap<String, Object> getTodoData(HttpServletRequest request, Model model){
|
public HashMap<String, Object> getTodoData(HttpServletRequest request, Model model) throws SQLException{
|
||||||
HttpSession session = request.getSession();
|
HttpSession session = request.getSession();
|
||||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
Connection conn = Dao.getConnection();
|
|
||||||
int userNo = (int)session.getAttribute("userNo");
|
int userNo = (int)session.getAttribute("userNo");
|
||||||
ArrayList<TodoVo> list = todoService.selectAll(conn, userNo);
|
ArrayList<TodoVo> list = todoService.selectAll( userNo);
|
||||||
HashMap<Integer, Integer> boardMap = new HashMap<Integer, Integer>();
|
HashMap<Integer, Integer> boardMap = new HashMap<Integer, Integer>();
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(TodoVo vo : list){
|
for(TodoVo vo : list){
|
||||||
@@ -51,7 +47,6 @@ public class TodoController{
|
|||||||
|
|
||||||
session.setAttribute("todoMap", boardMap);
|
session.setAttribute("todoMap", boardMap);
|
||||||
|
|
||||||
Dao.close(conn);
|
|
||||||
|
|
||||||
map.put("list", list);
|
map.put("list", list);
|
||||||
|
|
||||||
@@ -62,7 +57,7 @@ public class TodoController{
|
|||||||
@RequestMapping(value = "/todoUpdate.do")
|
@RequestMapping(value = "/todoUpdate.do")
|
||||||
public HashMap<String, Object> todoUpdate(HttpServletRequest request,
|
public HashMap<String, Object> todoUpdate(HttpServletRequest request,
|
||||||
@RequestBody HashMap<String, Object> map,
|
@RequestBody HashMap<String, Object> map,
|
||||||
Model model){
|
Model model) throws SQLException{
|
||||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||||
HttpSession session =request.getSession();
|
HttpSession session =request.getSession();
|
||||||
HashMap<Integer, Integer> boardMap = (HashMap<Integer, Integer>)session.getAttribute("todoMap");
|
HashMap<Integer, Integer> boardMap = (HashMap<Integer, Integer>)session.getAttribute("todoMap");
|
||||||
@@ -80,7 +75,6 @@ public class TodoController{
|
|||||||
sub2= o2.toString();
|
sub2= o2.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection conn = Dao.getConnection();
|
|
||||||
if(!(check.equals("true") || check.equals("false")))
|
if(!(check.equals("true") || check.equals("false")))
|
||||||
{
|
{
|
||||||
returnMap.put("result", 0);
|
returnMap.put("result", 0);
|
||||||
@@ -92,18 +86,43 @@ public class TodoController{
|
|||||||
vo.setuSub1(sub1);
|
vo.setuSub1(sub1);
|
||||||
vo.setuSub2(sub2);
|
vo.setuSub2(sub2);
|
||||||
|
|
||||||
int result = todoService.update(conn, vo);
|
int result = todoService.update( vo);
|
||||||
returnMap.put("result", result);
|
returnMap.put("result", result);
|
||||||
}
|
}
|
||||||
Dao.close(conn);
|
|
||||||
return returnMap;
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/insertTodo.do")
|
@RequestMapping("/insertTodo.do")
|
||||||
public HashMap<String, Object> todoUpdate( HttpServletRequest request, @RequestBody HashMap<String, Object> map){
|
public HashMap<String, Object> insertTodo( HttpServletRequest request, @RequestBody HashMap<String, Object> map) throws SQLException{
|
||||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||||
int userno = (int)request.getSession().getAttribute("userNo");
|
int userno = (int)request.getSession().getAttribute("userNo");
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
HashMap<Integer, Integer> boardMap = (HashMap<Integer, Integer>)session.getAttribute("todoMap");
|
||||||
|
|
||||||
|
String content = (String)map.get("content");
|
||||||
|
String sub2 = (String)map.get("sub2");
|
||||||
|
String check = map.get("check").toString();
|
||||||
|
String lno = (String)map.get("lineNo");
|
||||||
|
System.out.println(lno);
|
||||||
|
int lineNo = Integer.parseInt(lno);
|
||||||
|
|
||||||
|
TodoVo vo = new TodoVo();
|
||||||
|
vo.setuContent(content);
|
||||||
|
vo.setuSub2(sub2);
|
||||||
|
vo.setuCheck(check);
|
||||||
|
vo.setUserno(userno);
|
||||||
|
|
||||||
|
int result = todoService.insert(vo);
|
||||||
|
|
||||||
|
if( result != 0 ){
|
||||||
|
vo = todoService.selectLast();
|
||||||
|
boardMap.put(lineNo, vo.getuNo());
|
||||||
|
returnMap.put("item", vo);
|
||||||
|
returnMap.put("result", "true");
|
||||||
|
}else{
|
||||||
|
returnMap.put("result", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package co.nook.app.user.dao;
|
package co.nook.app.user.dao;
|
||||||
|
|
||||||
import co.nook.app.common.Dao;
|
import co.nook.app.user.service.UserMapper;
|
||||||
import co.nook.app.user.service.UserService;
|
import co.nook.app.user.service.UserService;
|
||||||
import co.nook.app.user.vo.UserVo;
|
import co.nook.app.user.vo.UserVo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -13,70 +16,55 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
@Repository("userDao")
|
@Repository("userDao")
|
||||||
public class UserDao implements UserService{
|
public class UserDao implements UserService{
|
||||||
PreparedStatement psmt;
|
|
||||||
ResultSet rs;
|
JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UserDao (JdbcTemplate jdbcTemplate){
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<UserVo> allSelect(Connection conn){
|
public ArrayList<UserVo> allSelect(){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String SELECT_BY_ID = "select * from user where id = ?";
|
final String SELECT_BY_ID = "select * from user where id = ?";
|
||||||
@Override
|
@Override
|
||||||
public UserVo select(Connection conn, String id){
|
public UserVo select( String id ){
|
||||||
|
|
||||||
UserVo vo = null;
|
|
||||||
try {
|
try {
|
||||||
conn = Dao.getConnection();
|
return jdbcTemplate.queryForObject(SELECT_BY_ID, new UserMapper(), id );
|
||||||
psmt = conn.prepareStatement(SELECT_BY_ID);
|
} catch (EmptyResultDataAccessException e) {
|
||||||
psmt.setString(1, id);
|
// EmptyResultDataAccessException 예외 발생시 null 리턴
|
||||||
rs = psmt.executeQuery();
|
return null;
|
||||||
|
|
||||||
if(rs.next()){
|
|
||||||
vo = new UserVo();
|
|
||||||
vo.setUserNo(rs.getInt("userno"));
|
|
||||||
vo.setId(rs.getString("id"));
|
|
||||||
vo.setPassword(rs.getString("password"));
|
|
||||||
vo.setSalt(rs.getString("salt"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(SQLException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVo select(Connection conn, int userNo){
|
public UserVo select( int userNo){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final String INSERT = "INSERT INTO user (userno, id, password, salt) VALUES ( NEXTVAL(seq_user), ?, ?, ?)";
|
final String INSERT = "INSERT INTO user (userno, id, password, salt) VALUES ( NEXTVAL(seq_user), ?, ?, ?)";
|
||||||
@Override
|
@Override
|
||||||
public int insert(Connection conn, UserVo vo){
|
public int insert( UserVo vo){
|
||||||
int result = 0;
|
int n =jdbcTemplate.update(INSERT,
|
||||||
try{
|
vo.getId(),
|
||||||
psmt = conn.prepareStatement(INSERT);
|
vo.getPassword(),
|
||||||
psmt.setString(1, vo.getId());
|
vo.getSalt()
|
||||||
psmt.setString(2, vo.getPassword());
|
);
|
||||||
psmt.setString(3, vo.getSalt());
|
return n;
|
||||||
result = psmt.executeUpdate();
|
|
||||||
}catch(SQLException throwables){
|
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Connection conn, UserVo vo){
|
public int update( UserVo vo){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Connection conn, UserVo vo){
|
public int delete( UserVo vo){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main/java/co/nook/app/user/service/UserMapper.java
Normal file
20
src/main/java/co/nook/app/user/service/UserMapper.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package co.nook.app.user.service;
|
||||||
|
|
||||||
|
import co.nook.app.user.vo.UserVo;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class UserMapper implements RowMapper<UserVo>{
|
||||||
|
@Override
|
||||||
|
public UserVo mapRow(ResultSet rs, int rowNum) throws SQLException{
|
||||||
|
UserVo vo = new UserVo();
|
||||||
|
vo.setId(rs.getString("id"));
|
||||||
|
vo.setUserNo(rs.getInt("userno"));
|
||||||
|
vo.setPassword(rs.getString("password"));
|
||||||
|
vo.setSalt(rs.getString("salt"));
|
||||||
|
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,14 @@ package co.nook.app.user.service;
|
|||||||
import co.nook.app.user.vo.UserVo;
|
import co.nook.app.user.vo.UserVo;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface UserService{
|
public interface UserService{
|
||||||
public ArrayList<UserVo> allSelect(Connection conn);
|
public ArrayList<UserVo> allSelect() throws SQLException;
|
||||||
public UserVo select(Connection conn, String id);
|
public UserVo select(String id) throws SQLException;
|
||||||
public UserVo select(Connection conn, int userNo);
|
public UserVo select( int userNo) throws SQLException;
|
||||||
public int insert(Connection conn, UserVo vo);
|
public int insert( UserVo vo ) throws SQLException;
|
||||||
public int update(Connection conn, UserVo vo);
|
public int update( UserVo vo ) throws SQLException;
|
||||||
public int delete(Connection conn, UserVo vo);
|
public int delete( UserVo vo ) throws SQLException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,32 +20,32 @@ public class UserServiceImpl implements UserService{
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<UserVo> allSelect(Connection conn){
|
public ArrayList<UserVo> allSelect(){
|
||||||
return userDao.allSelect(conn);
|
return userDao.allSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVo select(Connection conn, String id){
|
public UserVo select( String id){
|
||||||
return userDao.select(conn, id);
|
return userDao.select( id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVo select(Connection conn, int userNo){
|
public UserVo select( int userNo){
|
||||||
return userDao.select(conn, userNo);
|
return userDao.select( userNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(Connection conn, UserVo vo){
|
public int insert( UserVo vo){
|
||||||
return userDao.insert(conn, vo);
|
return userDao.insert( vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Connection conn, UserVo vo){
|
public int update( UserVo vo){
|
||||||
return userDao.update(conn, vo);
|
return userDao.update( vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Connection conn, UserVo vo){
|
public int delete( UserVo vo){
|
||||||
return userDao.delete(conn, vo);
|
return userDao.delete( vo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package co.nook.app.user.web;
|
package co.nook.app.user.web;
|
||||||
|
|
||||||
import co.nook.app.HomeController;
|
import co.nook.app.HomeController;
|
||||||
import co.nook.app.common.Dao;
|
|
||||||
import co.nook.app.common.SHAEncrypt;
|
import co.nook.app.common.SHAEncrypt;
|
||||||
import co.nook.app.user.service.UserService;
|
import co.nook.app.user.service.UserService;
|
||||||
import co.nook.app.user.vo.UserVo;
|
import co.nook.app.user.vo.UserVo;
|
||||||
@@ -12,9 +11,8 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.HashMap;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class UserController{
|
public class UserController{
|
||||||
@@ -30,19 +28,19 @@ public class UserController{
|
|||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/join.do", method = RequestMethod.POST)
|
@RequestMapping(value = "/join.do", method = RequestMethod.POST)
|
||||||
public String joinProcess(@RequestParam String id, @RequestParam String pw, Model model){
|
public String joinProcess(UserVo userVo, Model model) throws SQLException{
|
||||||
Connection conn = Dao.getConnection();
|
|
||||||
UserVo vo = new UserVo();
|
UserVo vo = new UserVo();
|
||||||
|
|
||||||
String salt = SHAEncrypt.generateSalt();
|
String salt = SHAEncrypt.generateSalt();
|
||||||
String encPw= SHAEncrypt.getEncrypt(pw, salt);
|
String encPw= SHAEncrypt.getEncrypt(userVo.getPassword(), salt);
|
||||||
|
|
||||||
vo.setId(id);
|
vo.setId(userVo.getId());
|
||||||
vo.setPassword(encPw);
|
vo.setPassword(encPw);
|
||||||
vo.setSalt(salt);
|
vo.setSalt(salt);
|
||||||
|
|
||||||
int result = userService.insert(conn, vo );
|
int result = userService.insert( vo );
|
||||||
Dao.close(conn);
|
|
||||||
String view = "login/login_form";
|
String view = "login/login_form";
|
||||||
if(result == 0){
|
if(result == 0){
|
||||||
view = "join/join";
|
view = "join/join";
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package co.nook.app.user.web;
|
package co.nook.app.user.web;
|
||||||
|
|
||||||
import co.nook.app.common.Dao;
|
|
||||||
import co.nook.app.common.SHAEncrypt;
|
import co.nook.app.common.SHAEncrypt;
|
||||||
import co.nook.app.user.service.UserService;
|
import co.nook.app.user.service.UserService;
|
||||||
import co.nook.app.user.vo.UserVo;
|
import co.nook.app.user.vo.UserVo;
|
||||||
@@ -10,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -25,13 +25,13 @@ public class UserRestController{
|
|||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping( value = "/userCheck.do", method= RequestMethod.POST)
|
@RequestMapping( value = "/userCheck.do", method= RequestMethod.POST)
|
||||||
public HashMap<String, Object> userCheck(@RequestBody HashMap<String, Object> map, Model model ){
|
public HashMap<String, Object> userCheck(@RequestBody UserVo userVo, Model model ) throws SQLException{
|
||||||
HashMap<String, Object> responseMap = new HashMap<String, Object>();
|
HashMap<String, Object> responseMap = new HashMap<String, Object>();
|
||||||
Connection conn = Dao.getConnection();
|
|
||||||
String id = (String)map.get("id");
|
|
||||||
|
|
||||||
UserVo vo = userService.select(conn, id);
|
String id = userVo.getId();
|
||||||
Dao.close(conn);
|
|
||||||
|
UserVo vo = userService.select(id);
|
||||||
|
|
||||||
if( vo == null ){
|
if( vo == null ){
|
||||||
responseMap.put("result", "false");
|
responseMap.put("result", "false");
|
||||||
}else{
|
}else{
|
||||||
@@ -43,19 +43,16 @@ public class UserRestController{
|
|||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping(value = "/loginCheck.do", method = RequestMethod.POST)
|
@RequestMapping(value = "/loginCheck.do", method = RequestMethod.POST)
|
||||||
public HashMap<String, Object> loginCheck(@RequestBody HashMap<String, Object> map, HttpServletRequest request, Model model){
|
public HashMap<String, Object> loginCheck(@RequestBody UserVo userVo, HttpServletRequest request, Model model) throws SQLException{
|
||||||
HashMap<String, Object> responseMap = new HashMap<String, Object>();
|
HashMap<String, Object> responseMap = new HashMap<String, Object>();
|
||||||
String id = (String)map.get("id");
|
|
||||||
String pw = (String)map.get("pw");
|
UserVo vo = userService.select(userVo.getId());
|
||||||
Connection conn = Dao.getConnection();
|
|
||||||
UserVo vo = userService.select(conn, id);
|
|
||||||
Dao.close(conn);
|
|
||||||
if(vo == null){
|
if(vo == null){
|
||||||
responseMap.put("result", "false");
|
responseMap.put("result", "false");
|
||||||
return responseMap;
|
return responseMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
String encPw = SHAEncrypt.getEncrypt(pw, vo.getSalt());
|
String encPw = SHAEncrypt.getEncrypt(userVo.getPassword(), vo.getSalt());
|
||||||
|
|
||||||
if( vo.getPassword().equals(encPw)){
|
if( vo.getPassword().equals(encPw)){
|
||||||
responseMap.put("result", "true");
|
responseMap.put("result", "true");
|
||||||
|
|||||||
@@ -6,6 +6,19 @@
|
|||||||
|
|
||||||
<!-- Root Context: defines shared resources visible to all other web components -->
|
<!-- Root Context: defines shared resources visible to all other web components -->
|
||||||
|
|
||||||
|
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
|
||||||
|
destroy-method="close">
|
||||||
|
<property name="driverClassName" value="org.mariadb.jdbc.Driver" />
|
||||||
|
<property name="url" value="jdbc:mariadb://coon.myds.me:3307/NookSearch" />
|
||||||
|
<property name="username" value="minechost" />
|
||||||
|
<property name="password" value="Ahstmxj5zos1!" />
|
||||||
|
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- Spring JDBC 설정 -->
|
||||||
|
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||||
|
<property name="dataSource" ref="dataSource" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
$("#pwCheck").change(function(){
|
$("#pwCheck").change(function(){
|
||||||
if($("#pwCheck").val() != $("#pw").val()){
|
if($("#pwCheck").val() != $("#password").val()){
|
||||||
$("#pwCheck").focus();
|
$("#pwCheck").focus();
|
||||||
$("#pwCheckHelp").show();
|
$("#pwCheckHelp").show();
|
||||||
}else{
|
}else{
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
json.id = str;
|
json.id = str;
|
||||||
var parsed = JSON.stringify(json);
|
var parsed = JSON.stringify(json);
|
||||||
$("#btn_join").off();
|
$("#btn_join").off();
|
||||||
if($("#pwCheck").val() == $("#pw").val()) {
|
if($("#pwCheck").val() == $("#password").val()) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "userCheck.do",
|
url: "userCheck.do",
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
if($("#pwCheck").val() != $("#pw").val()){
|
if($("#pwCheck").val() != $("#password").val()){
|
||||||
$("#pwCheck").focus();
|
$("#pwCheck").focus();
|
||||||
$("#pwCheckHelp").show();
|
$("#pwCheckHelp").show();
|
||||||
}else{
|
}else{
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>비밀번호</label>
|
<label>비밀번호</label>
|
||||||
<input type="password" id="pw" name="pw" class="form-control" placeholder="Password" required>
|
<input type="password" id="password" name="password" class="form-control" placeholder="Password" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>비밀번호 확인</label>
|
<label>비밀번호 확인</label>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
function login(){
|
function login(){
|
||||||
let json = {};
|
let json = {};
|
||||||
json.id = $("#id").val();
|
json.id = $("#id").val();
|
||||||
json.pw = $("#pw").val();
|
json.password = $("#password").val();
|
||||||
let parsed = JSON.stringify(json);
|
let parsed = JSON.stringify(json);
|
||||||
|
|
||||||
console.log(parsed);
|
console.log(parsed);
|
||||||
@@ -63,8 +63,8 @@
|
|||||||
<label for="id">ID : </label>
|
<label for="id">ID : </label>
|
||||||
<input class="form-control" type="text" id="id" name="id" aria-describedby="idHelp">
|
<input class="form-control" type="text" id="id" name="id" aria-describedby="idHelp">
|
||||||
<small id="idHelp" class="form-text text-muted">아이디를 입력해주세요</small>
|
<small id="idHelp" class="form-text text-muted">아이디를 입력해주세요</small>
|
||||||
<label for="pw">PW : </label>
|
<label for="password">PW : </label>
|
||||||
<input class="form-control" type="password" id="pw" name="pw" aria-describedby="pwHelp">
|
<input class="form-control" type="password" id="password" name="password" aria-describedby="pwHelp">
|
||||||
<small id="pwHelp" class="form-text text-muted">비밀번호를 입력해주세요</small>
|
<small id="pwHelp" class="form-text text-muted">비밀번호를 입력해주세요</small>
|
||||||
<button id="btn_login" class="btn btn-primary" type="button">로그인</button>
|
<button id="btn_login" class="btn btn-primary" type="button">로그인</button>
|
||||||
<button id="btn_join" class="btn btn-primary" type="button">회원가입</button>
|
<button id="btn_join" class="btn btn-primary" type="button">회원가입</button>
|
||||||
|
|||||||
@@ -57,12 +57,11 @@
|
|||||||
function removeDel($input){
|
function removeDel($input){
|
||||||
$input.unwrap("del");
|
$input.unwrap("del");
|
||||||
}
|
}
|
||||||
|
function showHideCheck($button, bool){
|
||||||
|
let $img = $button.find("i");
|
||||||
|
if(!bool){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function toggleCheck($button){
|
|
||||||
let $img = $button.find("svg");
|
|
||||||
if($img.hasClass("leafCheck")){
|
|
||||||
$img.removeClass("leafCheck");
|
$img.removeClass("leafCheck");
|
||||||
$img.hasClass("leafHide");
|
$img.hasClass("leafHide");
|
||||||
$img.hide();
|
$img.hide();
|
||||||
@@ -71,6 +70,24 @@
|
|||||||
$img.removeClass("leafHide");
|
$img.removeClass("leafHide");
|
||||||
$img.addClass("leafCheck");
|
$img.addClass("leafCheck");
|
||||||
$img.show();
|
$img.show();
|
||||||
|
console.log("leaf Show");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toggleCheck($button){
|
||||||
|
let $img = $button.find("svg");
|
||||||
|
if($img.hasClass("leafCheck")){
|
||||||
|
console.log("leaf HIde");
|
||||||
|
$img.removeClass("leafCheck");
|
||||||
|
$img.hasClass("leafHide");
|
||||||
|
$img.hide();
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$img.removeClass("leafHide");
|
||||||
|
$img.addClass("leafCheck");
|
||||||
|
$img.show();
|
||||||
|
console.log("leaf Show");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,18 +331,20 @@
|
|||||||
$addTodoTr = $("<tr>");
|
$addTodoTr = $("<tr>");
|
||||||
$tbodyTodo.append($addTodoTr);
|
$tbodyTodo.append($addTodoTr);
|
||||||
//숫자 부분
|
//숫자 부분
|
||||||
|
++count;
|
||||||
let $td = $("<td>");
|
let $td = $("<td>");
|
||||||
$addTodoTr.append($td);
|
$addTodoTr.append($td);
|
||||||
$td.html((count+1).toString());
|
$td.html(count.toString());
|
||||||
|
|
||||||
//체크 박스 부분
|
//체크 박스 부분
|
||||||
$td = $("<td>");
|
$td = $("<td>");
|
||||||
$addTodoTr.append($td);
|
$addTodoTr.append($td);
|
||||||
let $btnLeaf = $("<ct:button_leaf />");
|
let $btnLeaf = $("<ct:button_leaf />");
|
||||||
|
showHideCheck($btnLeaf, false);
|
||||||
$btnLeaf.on("click", { button : $btnLeaf } , toggleCheckByEvent);
|
$btnLeaf.on("click", { button : $btnLeaf } , toggleCheckByEvent);
|
||||||
|
|
||||||
$td.append($btnLeaf);
|
$td.append($btnLeaf);
|
||||||
|
|
||||||
//content 부분
|
//content 부분
|
||||||
$td = $("<td>");
|
$td = $("<td>");
|
||||||
$addTodoTr.append($td);
|
$addTodoTr.append($td);
|
||||||
@@ -355,17 +374,40 @@
|
|||||||
$btnSave.on("click", insertLine);
|
$btnSave.on("click", insertLine);
|
||||||
}
|
}
|
||||||
function insertLine() {
|
function insertLine() {
|
||||||
|
let $tr = $(this).parents("tr");
|
||||||
let content = $(this).parent().parent().find("input[name='ipTodo']").val();
|
let content = $(this).parent().parent().find("input[name='ipTodo']").val();
|
||||||
let sub2 = $(this).parent().parent().find("input[name='ipMax']").val();
|
let sub2 = $(this).parent().parent().find("input[name='ipMax']").val();
|
||||||
let check = $(this).parents("tr").find("svg").hasClass("leafCheck");
|
let check = $tr.find("svg").hasClass("leafCheck");
|
||||||
|
let lineNo = $tr.find("td:first").html();
|
||||||
|
|
||||||
|
|
||||||
console.log("content : "+content);
|
let json= {};
|
||||||
console.log("sub2 : " + sub2);
|
json.content= content;
|
||||||
console.log("check : " + check);
|
json.sub2 = sub2;
|
||||||
|
json.check = check;
|
||||||
|
json.lineNo = lineNo;
|
||||||
|
|
||||||
|
let parsed = JSON.stringify(json);
|
||||||
//controller에 추가
|
//controller에 추가
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "insertTodo.do",
|
||||||
|
data: parsed,
|
||||||
|
datatype: "json",
|
||||||
|
contentType: "application/json",
|
||||||
|
success: function (data) {
|
||||||
|
if(data.result == "true"){
|
||||||
|
$tr.remove();
|
||||||
|
alert("입력 성공");
|
||||||
|
AddTr(parseInt(lineNo)-1, data.item);
|
||||||
|
}else{
|
||||||
|
alert("입력 실패");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user