Controller 부분

1
2
3
4
5
6
@RequestMapping(value = "regist")
public ModelAndView regist(HttpServletRequest req) {
    String id = req.getParameter("email");
    String pw = req.getParameter("password");
    return service.regist(id, pw);
}
cs

req.getParameter("JSP_NAME");
jsp에서 form 안에있는 name값을 가져온다.

service 부분
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Service
public class TestService {
 
    @Autowired
    SqlSession sqlSession;
    
    TestInterface inter = null;
    
    // 회원가입
    public ModelAndView regist(String id, String pw) {
        ModelAndView mav = new ModelAndView();
        inter = sqlSession.getMapper(TestInterface.class);
        int success = inter.regist(id, pw);
        
        mav.setViewName("redirect:/");
        return mav;
    }
 
}
cs


DTO 부분
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class TestDTO {
    private String test_id;
    private String test_pw;
 
    public String getTest_id() {
        return test_id;
    }
 
    public void setTest_id(String test_id) {
        this.test_id = test_id;
    }
 
    public String getTest_pw() {
        return test_pw;
    }
 
    public void setTest_pw(String test_pw) {
        this.test_pw = test_pw;
    }
}
cs


DAO interface 부분

1
2
3
public interface testInterface {
    int regist(String id, String pw);
}
cs
DAO sqlMapper 부분

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.test.dao.TestInterface">
    <insert id="regist">
        INSERT INTO testmem(test_id, test_pw)
            VALUES(#{param1}, #{param2})
    </insert>
</mapper>
cs


JSP 부분


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="UTF-8">
    <title>회원가입</title>
</head>
 
<body>
    <form action="regist" method="post">
        <input type="email" id="email" name="email" placeholder="email"/>
        <input type="password" id="password" name="password" placeholder="password"/>
        <input type="submit" />
    </form>
 
</body>
 
</html>
cs

form 태그의 action은 컨트롤러에서 @RequestMapping(value = "JSP_ACTION") 에 들어간다.
input 태그 안에 name은 서버로 넘겨지는 값.


'프로그래밍 > Spring' 카테고리의 다른 글

jquery를 이용한 ajax json  (0) 2017.08.28
MyBatis 세팅  (0) 2016.06.15
STS설정 및 스프링 한글깨짐 방지 설정  (0) 2016.06.13

+ Recent posts