게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
selectOne은 어떠한 데이터 타입으로 주고 받아야 하나요?
게시물ID : programmer_13511짧은주소 복사하기
작성자 : 닉눼윔
추천 : 0
조회수 : 1846회
댓글수 : 3개
등록시간 : 2015/09/24 22:58:32

안녕하세요 잘 모르는게 있어 글을 올리게 되었습니다.

다름이 아니라 SqlSession에서 selectOne을 사용하려면 어떠한 데이터 타입이 필요한지 몰라서요..
db는 자동으로 증가하는 idx 그리고 val1, val2, val3 이렇게 있습니다(idx만 int형 나머지 varchar)
idx 값을 받아서 입력한 idx에 해당되는 것만 보여주려고 하는데요(select * from test where idx=12 뭐 이런식으로..)

전체를 다 보여주려면
List<HashMap<String, String>> outputs = sqlSession.selectList("userControlMapper.selectAll");
ModelAndView mav=new ModelAndView("result","m" , outputs);
return mav;

이런식으로 받아오던데
하나만 선택해서 받아오는 것은 어떻게 하는지 잘 모르겠습니다...

도움을 주시면 정말 감사하겠습니다 ㅠㅠ

mapper.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace= "userControlMapper" >
    <select id ="selectAll" parameterType="java.util.HashMap" resultType= "java.util.HashMap">
        select * from tsst
    </select>
    
    <select id="select" parameterType="java.util.HashMap" resultType= "java.util.HashMap">
        select * from tsst where idx = #{idx}
    </select>
    
    <insert id="insert">
        insert into tsst(val1, val2, val3) value(#{val1}, #{val2}, #{val3})
    </insert>
     
    <delete id="delete" parameterType="int">
        delete from tsst where idx = #{idx}
    </delete>
    
    <update id="update">
        update tsst set val1=#{val1}, val2=#{val2}, val3=#{val3} where idx=#{idx}
    </update>
 
</mapper>
cs

 
HomeController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
    @Autowired
    private SqlSession sqlSession;
    
    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/result", method = RequestMethod.POST)
    public ModelAndView home(Locale locale, Model model, HttpServletRequest request, HttpServletResponse response) 
    {
        try
        {
            request.setCharacterEncoding("UTF-8");
            String val1 = request.getParameter("val1");
            String val2 = request.getParameter("val2");
            String val3 = request.getParameter("val3");
            String check = request.getParameter("check");
            
            if(check.equals("select"))
            {
                int idx = Integer.parseInt(request.getParameter("selectIdx"));
                /*                
                여기가 문제!!!
                */
            }            
            else
            {
                try{
                    if(check.equals("insert"))
                    {
                        Vo vo = new Vo(val1, val2, val3);
                        sqlSession.insert("userControlMapper.insert", vo);
                    }
                    
                    else if(check.equals("delete"))
                    {
                        Vo vo = new Vo(val1, val2, val3);
                        int idx = Integer.parseInt(request.getParameter("delIdx"));
                        sqlSession.delete("userControlMapper.delete", idx);
                    }
                    
                    else if(check.equals("update"))
                    {
                        int idx = Integer.parseInt(request.getParameter("upIdx"));
                        Vo vo = new Vo(idx, val1, val2, val3);
                        sqlSession.update("userControlMapper.update", vo);
                    }
                }
                catch(Exception e){                    
                }
                List<HashMap<StringString>> outputs = sqlSession.selectList("userControlMapper.selectAll");
                ModelAndView mav=new ModelAndView("result","m" , outputs);
                
                return mav;
            }
        }        
        catch(Exception e){            
        }
        
        return null;
    }    
}
 
cs




Vo.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class Vo {
    
    private String val1;
    private String val2;
    private String val3;
    private int idx;
 
    public Vo(String val1, String val2, String val3){
        this.val1 = val1;
        this.val2 = val2;
        this.val3 = val3;
    }
    
    public Vo(int idx, String val1, String val2, String val3){
        this.idx = idx;
        this.val1 = val1;
        this.val2 = val2;
        this.val3 = val3;
    }
    
    public int getIdx(){
        return idx;
    }
    public void setIdx(){
        this.idx = idx;
    }
    
    public String getVal1() {
        return val1;
    }
    public void setVal1(String val1) {
        this.val1 = val1;
    }
    public String getVal2() {
        return val2;
    }
    public void setVal2(String val2) {
        this.val2 = val2;
    }
    public String getVal3() {
        return val3;
    }
    public void setVal3(String val3) {
        this.val3 = val3;
    }
}
 
cs



캡처.PNG






꼬릿말 보기
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호