자동망치 기능

  • view쪽을 수정하고 재실행하지 않고 망치를 눌러서 수정된 화면을 확인할 수 있다.(ctrl+shift+r)

intelliJ 위쪽 메뉴바

초록색 망치모양을 클릭한 후 화면에서 ctrl+shift+r을 눌러 새로고침한다.

 

자동망치 설정

  • 의존성 추가
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>

 

  • properties 설정
 <!--- application.yml--->
    devtools:
      livereload:
        enabled: false
      add-properties: false
      restart:
        enabled: false
        
<!--- application-local.yml--->
    devtools:
      livereload:
        enabled: true
      add-properties: true
      restart:
        enabled: false

 

  • Edit Configuration

초록 망치 옆 네모칸 클릭

Active profiles를 local로 설정해준다

'Web > Spring' 카테고리의 다른 글

[Pageable] 페이징 처리 - 기본  (0) 2021.08.06
[배경] JPA vs JDBC, JPA vs Mybatis, JPA vs Spring Data JPA  (0) 2021.08.06
[설정] application.properties  (0) 2021.08.04
[CRUD] R구현  (0) 2021.08.02
[CRUD] C구현  (0) 2021.08.02

효율성을 극대화하기 위해

 

DB 환경

효율성을 높이기 위해 인덱스를 이용해야 한다.

 

인덱스 예시

위와 같이 키 마다 묶여있는 칼럼들이 있는데 그것을 활용해야 쿼리를 수행할 때 빠르게 찾을 수 있다.

만약 저 인덱스 짝들이 맞지 않는다면 전체 테이블을 돌면서 찾게 되고 수행 속도가 느려진다.

데이터양이 적으면 크게 상관 없겠지만 데이터양은 무궁무진하기 때문에.. 효율성이 중요!!!!!!

 

❗ DB수업을 듣지 않고 쿼리를 짜려니 효율성이 떨어진다... 이번 2학기 DB 수업 들으면서 쿼리 짜는 연습이 필요해 보인다. ❗

 

비효율적인 쿼리
효율적인 쿼리

두 개의 쿼리문을 비교해보면 비효율적인 쿼리는 인덱스를 활용하지 않았고 효율적인 쿼리는 인덱스(groupby구문 쪽)를 모두 활용했기 때문에 차이점이 생긴다!

'Computer Science > DataBase' 카테고리의 다른 글

[NoSQL] mongoDB  (0) 2022.12.12
[설정] DB 환경설정하기  (0) 2021.08.06

❗ 환경 : mariaDB, HeidiSQL ❗

❗ 참고로 mariaDB 설치시 HeidiSQL은 자동으로 설치된다 ❗

 

local환경 생성

  • local 세션 세팅

세션 설정

세션의 이름과 암호는 최고 관리자(root)의 암호를 적고 열기 버튼을 누른다

암호는 꼭 기억해둘 것!!

  • 생성한 로컬에 오른쪽 마우스버튼 클릭 → 새로 생성 → 데이터베이스

DB설정

이름은 자신이 만들어둔 C:(로컬 디스크) 안 이름과 같게 설정! spring과 연결 할 땐 properties 이름도 같게 만들어줘야함!!

  • 사용자 추가

사람 모양 아이콘 클릭

추가 버튼을 누르고 사용자 이름과 암호를 spring에 맞게 입력한다.

다음으로 객체 추가 버튼을 눌러 전에 생성한 DB를 클릭하고 체크박스를 알맞게 체크해준다.

❗ 전체 권한 체크는 모든 생성된 DB 관련이니 건들지 말것! 객체 추가를 해준다 ❗

 

'Computer Science > DataBase' 카테고리의 다른 글

[NoSQL] mongoDB  (0) 2022.12.12
[Query] 쿼리의 효율성 - Index  (0) 2021.08.06

properties 파일

  • Spring에서 서비스에 필요한 설정 정보 등을 텍스트 파일 형태로 관리하기 위한 설정 파일(외부 설정 파일)
  • Spring boot가 App을 구동할 때 자동으로 로딩하게 해 준다
  • properties 말고 YAML파일도 있음(application.properties → application.yml)
  • 우선순위
    • 유저 홈 디렉터리에 있는 spring-boot-dev-tools.properties
    • 테스트에 있는 @TestPropertySource
    • @SpringBootTest annotation의 properties attribute
    • command line argument
    • SPRING_APPLICATION_JSON에 들어있는 property
    • ServletConfig 파라미터
    • ServletContext 파라미터
    • ... https://100100e.tistory.com/378 (참고)

 

Profile에 따른 환경 구성 분리

DB의 경우 로컬(local), 개발(dev), 운영에 따라 각각의 설정값이 모두 다를 수 있다!

YAML파일의 경우 --- 을 사용해 나누거나 파일을 복사해 이름을 변경해 사용.

--- 으로 구분
이름으로 구분

properties 또한 필요에 의해 나눠준다.

이름으로 구분

이를 IntelliJ에서 실행할 때 Edit Configurations 메뉴를 클릭하고 Run/Debug Configurations 창에서 Active Profiles 값을 설정해주고 실행

 

❗ 주로 local에서 실행할듯...? 자동망치는 local이랑 yaml 파일 설정 고치면 가능하다.. 이는 좀 이따가.. ❗

'Web > Spring' 카테고리의 다른 글

[배경] JPA vs JDBC, JPA vs Mybatis, JPA vs Spring Data JPA  (0) 2021.08.06
[설정] 자동망치 기능  (0) 2021.08.06
[CRUD] R구현  (0) 2021.08.02
[CRUD] C구현  (0) 2021.08.02
[JPA] 데이터베이스 생성 또는 초기화  (0) 2021.08.02

fontawesome 아이콘 삽입

https://fontawesome.com/

 

Font Awesome

The world’s most popular and easiest to use icon set just got an upgrade. More icons. More styles. More Options.

fontawesome.com

위의 사이트에서 원하는 아이콘을 찾는다! (pro 붙어있는 것은 유료이다)

 

HTML파일 안에 script 추가

<!DOCTYPE html>
<html>
  <head>
    <script src="https://use.fontawesome.com/releases/v5.2.0/js/all.js"></script>
  </head>
  <body></body>
</html>

 

사이트에서 원하는 아이콘을 찾으면 <i>태그를 복사한 후 HTML파일에 붙여 넣는다.

<!DOCTYPE html>
<html>
  <head>
    <script src="https://use.fontawesome.com/releases/v5.2.0/js/all.js"></script>
  </head>
  <body>
    <div style="font-size: 30px;">
      <i class="fas fa-smile"></i>
    </div>
  </body>
</html>

'Web > Front' 카테고리의 다른 글

[HTML] 템플릿 파일 적용 규칙  (0) 2021.07.30
[Javascript] window.location 객체  (0) 2021.07.30
[HTML] HTML 템플릿 다운로드 사이트  (0) 2021.07.30
[ERROR] 500에러 관련  (0) 2021.07.30
[ERROR] static파일 적용 관련  (0) 2021.07.30

CRUD

  • Create (INSERT)
  • Read (SELECT)
  • Update (UPDATE)
  • Delete (DELETE)

Read 구현

필요한 것

  • DB table에서 원하는 내용을 꺼내올 것
  • list 화면에 내용들을 list로 보여줌
  • list들 중 하나를 클릭하면 read화면이 떠서 볼 수 있게

 

❗ C구현에서 했던 filter와 service, repository들을 그대로 활용할 예정 ❗

먼저 list화면을 구현

<!DOCTYPE HTML>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

<head>
  <th:block th:replace="fragments/head :: head"></th:block>
  <link rel="stylesheet" th:href="@{/static/assets/css/project-list.css}" type="text/css"/>
  <style>
    h2, p {
      font-weight: bold;
    }
    a {
      text-decoration: none;
      color: #777777;
    }
  </style>
</head>

<body class="is-preload">
<div id="wrapper">
  <th:block th:replace="fragments/top :: top"></th:block>
  <div id="main">
    <article id="work" class="panel">
      <header>
        <h2>Project</h2>
      </header>
      <p>
        A field of interest :
        <span style="font-weight: lighter">Cloud(AWS, OpenStack), WEB(Spring), DevOps</span>
      </p>

      <table class="type09">
        <thead>
        <tr>
          <th scope="col">No.</th>
          <th scope="col">Progress Date</th>
          <th scope="col">Project Title</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="p: ${projectList}">
          <td scope="row" style="width: 50px"><a th:text="${p.id}" th:href="|@{/project/read}/${p.id}|"></a> </td>
          <td><a th:text="${p.date}" th:href="|@{/project/read}/${p.id}|"></a> </td>
          <td><a th:text="${p.title}" th:href="|@{/project/read}/${p.id}|"></a> </td>
        </tr>
        </tbody>
      </table>
      <a class="addButton" th:text="|ADD|" th:href="|@{/project/edit}|"></a>
    </article>
  </div>
</div>
<th:block th:replace="fragments/footer :: footer"></th:block>
<th:block th:replace="fragments/common-script :: common-script"/>
</body>
</html>

 

읽을 read화면도 구현

<!DOCTYPE HTML>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

<head>
  <th:block th:replace="fragments/head :: head"></th:block>
  <link rel="stylesheet" th:href="@{/static/assets/css/project-read.css}" type="text/css"/>
  <style>
    h2 {
      font-weight: bold;
    }
  </style>
</head>

<body class="is-preload">
<div id="wrapper">

  <th:block th:replace="fragments/top :: top"></th:block>
  <div id="main">
    <article id="work" class="panel" th:object="${project}">
      <h2>Project</h2>
      <div class="mb-3">
        <h4 class="title" th:text="*{title}"></h4>
      </div>
      <div class="mb-3">
        <h5 class="date" th:text="*{date}"></h5>
      </div>
      <hr class="one">
      <div class="mb-3">
        <h5 class="purpose" th:text="*{purpose}"></h5>
      </div>
      <hr class="two">
      <div class="mb-3">
        <h5 class="technology" th:text="*{technology}"></h5>
      </div>
      <hr class="two">
      <div class="mb-3">
        <h5 class="address" th:text="*{address}"></h5>
      </div>

    </article>
  </div>
</div>
<th:block th:replace="fragments/footer :: footer"></th:block>
<th:block th:replace="fragments/common-script :: common-script"/>
</body>
</html>

 

이 화면들을 띄워줄 controller 구현

@Controller
@RequiredArgsConstructor
@RequestMapping("/project")
public class ProjectController {

 @NonNull
  private final ProjectService projectService;

  @GetMapping("")
  public String list(Model model, Pageable pageable, ProjectFilter filter) {

    model.addAttribute("projectList", projectService.findAllByFilter(pageable, filter));
    model.addAttribute("filter", filter);
    return "project/list";
  }
  
   @GetMapping("/read/{id}")
  public String read(@PathVariable Integer id, Model model) {

    Project project = projectService.findById(id).orElseThrow(DataNotFoundException::new);
    model.addAttribute("project",project);

    return "project/read";
  }
}

여기까지 구현하면 CR구현이 완성되었다!

list 화면
read 화면

 

❗ 코드 관련 문법이나 필요한 내용들은 따로 정리할 예정이며 UD는 천천히 구현해볼 예정이다! ❗

'Web > Spring' 카테고리의 다른 글

[설정] 자동망치 기능  (0) 2021.08.06
[설정] application.properties  (0) 2021.08.04
[CRUD] C구현  (0) 2021.08.02
[JPA] 데이터베이스 생성 또는 초기화  (0) 2021.08.02
[ERROR] Pageable import  (0) 2021.08.02

+ Recent posts