TIL 2022-11-24 spring boot 페이징 라이브러리

JYR00·2022년 11월 24일
0

TIL

목록 보기
40/60

새 프로젝트 생성

pageTest



7개 선택

주석처리 해놔야 연결됨

SELECT * FROM sakila.customer;

SELECT * FROM sakila.customer;

use sakila;

select host, user,authentication_string from user;

show grants for 'test1'@'localhost';


-- grant all privileges ON sakila.customer;
use sakila;
create view customers as select * from sakila.customer;

use mysql;
select host, user,authentication_string from user;

show grants for 'test1'@'localhost';

grant all privileges on sakila.customers to 'test1'@'localhost';

view 테이블 생성 -> sakila.customers;



package com.bitc.pagetest.configuration;

import com.zaxxer.hikari.HikariConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("classpath:/application.properties")
public class DatabaseConfiguration {

    @Autowired
    private ApplicationContext applicationContext;
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.hikari")
    public HikariConfig hikariConfig(){
        return new HikariConfig();
    }
}


여기까지 하고 그레이들 주석 해제
주석해제하면 붉은 색 사라진다

configuration에 추가

resource->sql->sql-customer.xml 생성

mybatis -3에서 제공해줌
https://mybatis.org/mybatis-3/getting-started.html










page.html 생성

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container mt-5 p-5">
  <div class="row">
    <div class="col-sm">
      <table class="table table-hover table-striped">
        <thead>
        <tr>
          <th>고객번호</th>
          <th>이름</th>
          <th>이메일</th>
          <th>등록일</th>
          <th>수정일</th>
        </tr>
        </thead>
        <tbody>
        <tr th:if="${#lists.size(customersList)}>0" th:each="item:${customersList}">
          <td th:text="${item.customerId}"></td>
          <td th:text="|${item.lastName} ${item.firstName}|"></td>
          <td th:text="${item.email}"></td>
          <td th:text="${item.createDate}"></td>
          <td th:text="${item.lastUpdate}"></td>
        </tr>
        <tr th:unless="${#lists.size(customersList)}>0">
          <td>조회된 내용이 없습니다</td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>
</body>
</html>




실행화면

build-gradle


applicationproperties

controller변경

service에 넣은 값 impl에도 넣어줌


Impl에 메서드 구현

alt enter로 메서드 추가

mapper에 추가됨

sql-customers.xml에 추가








에러발견


해결 -> .getList() 추가
customerList만 있으면 컴퓨터가 인식을 잘 못함

그렇게 바꾸면


위에 페이지 번호 넣을 수 있고 고객 번호도 확인 가능



이 친구가 선언 되거나 사용된 위치를 알고 싶다면 아래와 같이 수행하라

bootstrap pagenation 페이지 참고함


jsp를 자동으로 ㅏㄱ져오는 사이트









오늘의 디버깅





요롷게

빨간줄 사라짐
업로드중..























0개의 댓글