본문 바로가기

spring/소스코드

kakaoAPI를 이용한 책검색-검색개수,마지막페이지 여부

<com.example.web>-<DaumAPI.java>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
import org.springframework.stereotype.Controller;
 
@Controller
public class DaumController {
    @RequestMapping("book")
    public String book() {
        return "book";
    }
    
    
}
 
 
 
 

<src>-<main>-<webapp>-<WEB-INF>-<views>-<book.jsp>

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>카카오 도서 검색</title>
    <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
    <link href="${pageContext.request.contextPath}/resources/style2.css" rel="stylesheet">
</head>
<body>
    <!-- 타이틀 -->
    <h1>[카카오 도서 검색]</h1>
    <!-- 검색 & 전체데이터 개수-->
    <div>
        검색: &nbsp;<input type="text" value="자바" id="query">
        <input type="button" value="검색" id="btnSearch">
        <span id="total"></span>
    </div>
    <!-- template -->
    <div id="container"></div>
    <script id="temp" type="text/x-handlebars-template">
    {{#each documents}}
    <div class="box">
        <img src="{{thumbnail}}" width=90 height=120>
        제목:<div class="title">{{title}}</div>
        저자:<div class="authors">{{authors}}</div>
        가격:<div class="price">{{price}}</div>
    </div>
    {{/each}}
    </script>
    <!-- 더보기 기능 -->
    <button id="btnMore">더보기</button>
</body>
    <script>
    //전역 변수
    var page=1;
    var query=$("#query").val();
    var is_end=false;
 
    //페이지가 끝났으면 자료를 더 보여주지 않게 하는 기능
    $("#btnMore").on("click",function(){
        if(!is_end){
            page += 1;
            getList();    
        }        
    });    
    //검색기능
    $("#btnSearch").on("click"function(){
        
        page=1;
        $("#container").html("");
        query=$("#query").val();
        getList();
    });
    $("#query").keydown(function(key){
        
        if(key.keyCode==13){
            page=1;
            $("#container").html("");
            query=$("#query").val();
            getList();
        }
    });
    //$.ajax
    getList();
    function getList(){
        $.ajax({
            type:"get",
            headers:{"Authorization":"KakaoAK 6baa3500ff42695b48d705aa87132cb3"},
            dataType:"json",
            data:{"query":query,"page":page,"size":"5"},
            success:function(data){
                var temp=Handlebars.compile($("#temp").html());
                $("#container").append(temp(data));
                $("#total").html(data.meta.total_count);
                //$("#container").html(temp(data));내용이 refresh
                //$("#container").appned(temp(data));내용이 추가
                is_end=data.meta.is_end;
            }
        });
    }
    </script>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

<src>-<main>-<webapp>-<resource>-<style2.css>

 

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
@CHARSET "UTF-8";
#container {
    background: lightyellow;
    width: 600px;
    overflow: hidden;
}
 
.box {
    width: 100px;
    margin: 10px;
    float: left;
    
 
 
}
    
    
 
 
.author {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    font-size: 12px;
    color: violet;
    text-align: center;
}
 
.price {
    font-size: 12px;
    text-align: center;
    color: violet;
}
 
#darken-background {
    position: absolute;
    top: 0px;
    left: 0px;
    right: 0px;
    height: 100%;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow-y: scroll;
    display: none;
}
 
#lightbox {
    width: 700px;
    margin: 20px auto;
    padding: 15px;
    border: 1px solid #333333;
    border-radius: 5px;
    background: white;
    box-shadow: 0px 5px 5px rgba(34, 25, 25, 0.4);
    text-align: center;
}