ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Springboot Db기록Ex
    Search: Spring Spring 2022. 9. 26. 20:43

     

    2022.08.06 - Vsc Spring Boot 사용 준비

    2022.09.25 - Vsc Spring Boot 설치

    2022.09.25 - Springboot Mustache 준비

     

    의존관계

     

    dependencies {
    	...
    	implementation 'org.springframework.boot:spring-boot-starter-mustache'
    	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    	implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
    	implementation group: 'com.h2database', name: 'h2', version: '2.1.214'
    	...
    }

     

    DatabaseEngine

     

    2022.09.26 - H2 Database Engine

    2022.09.26 - Springboot에 H2 database 사용

     

    ApplicationProperties

    application.properties

    #server.port=8081
    
    spring.jpa.hibernate.ddl-auto=create
    
    # DB 연결
    spring.datasource.driver-class-name=org.h2.Driver
    #spring.datasource.url=jdbc:h2:~/test
    spring.datasource.url=jdbc:h2:tcp://localhost/~/test
    spring.datasource.username=sa
    spring.datasource.password=

     

    DaoEntity

    MustacheTest1Entity1.java

    @Entity
    public class MustacheTest1Entity1 { //plan Mustache1Dao1
    
        @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
        public Long mId;
    
        @Column
        String mTitle;
    
        @Column
        String mContent;
    
        public MustacheTest1Entity1(Long id, String title, String content) {
            this.mId = id;
            this.mTitle = title;
            this.mContent = content;
        }
    }

     

    Repository

    MustacheTest1Repository1.java

    package com.test1.web1;
    
    import org.springframework.data.repository.CrudRepository;
    
    public interface MustacheTest1Repository1 extends CrudRepository<MustacheTest1Entity1, Long> {
        
    }

     

    Form

    MustacheTest1Form1.java

    public class MustacheTest1Form1 {
        
        public String mTitle, mContent;
    
        public MustacheTest1Form1(String title, String content) {
            this.mTitle = title;
            this.mContent = content;
        }
    
        @Override
        public String toString() {
            return "Mustache1Form1 [mContent=" + mContent + ", mTitle=" + mTitle + "]";
        }
    
        public MustacheTest1Entity1 toEntity() {
            return new MustacheTest1Entity1(null, mTitle, mContent);
        }
    }

     

     

    WriteHtml

    mustache1write.mustache

    <form action="/mustache1/create" method="post">
        <div>
            <label class="form-label">Title</label>
            <input type="text" name="title">
        </div>
        <div>
            <label class="form-label">Content</label>
            <textarea name="content"></textarea>
        </div>
        <button type="submit">sm</button>
    </form>

     

    실행결과

     

    http://localhost:8080/mustache1/write

     

     

    암호: infos

    SpringbootGradle1_H2db.7z
    0.06MB

     

    'Spring' 카테고리의 다른 글

    PathVariable Url경로에서 값 읽기  (0) 2022.09.28
    RequestParam Get방식 값 읽기  (0) 2022.09.28
    lombok  (0) 2022.09.27
    Jpa 참고 문서  (0) 2022.09.27
    spring.jpa.hibernate.hbm2ddl.auto  (0) 2022.09.26
    Springboot에 H2 database 사용  (0) 2022.09.26
    Springboot Mustache 준비  (0) 2022.09.25
    Springboot html 만들기  (0) 2022.09.25

    댓글