DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on

Full Stack Development with Spring Boot and React (အခန်း ၆)

ဒီအခန်းမှာတော့ MariaDB(MySql) server install လုပ်ပြီး Spring Boot ကနေလှမ်းချိတ်မှာဖြစ်ပါတယ်။

https://downloads.mariadb.org/ ကနေ နောက်ဆုံး stable version ကို download လုပ်ပြီး install လုပ်ပါ။

Image description

root user အတွက် password ပေးပါ။ ဒီ password ကို application.properties file မှာနောက်ကျရင် ထည့်ပေးရပါလိမ့်မယ်။

Image description

ပြီးရင်တော့ default setting အတိုင်းပဲထားပြီး install စလုပ်ပါ။

Image description

MariaDB installer မှာ Heidi SQL client ပါပါတယ်။ သူ့ကိုလည်း install လုပ်ပါ။

Installation ပြီးရင်တော့ Heidi SQL သုံးပြီး local မှာခုဏက install လုပ်လိုက်တဲ့ MariaDB server ထဲကို ဝင်ကြည့်လို့ရပါပြီ။ အဲဒီဆိုရင် cardb ဆိုတဲ့ database ကို create လုပ်လိုက်ပါ။

Image description

ပြီးရင်တော့ Database list ထဲမှာ အောက်ပါအတိုင်းရှိနေရမှာဖြစ်ပါတယ်။

Image description

Application ဆီကို ပြန်သွားပြီး pom.xml (Maven file) ထဲမှာ maria db ကို ချိတ်ဖို့ အတွက် client ကိုထည့်ပေးပါ။

<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
</dependency>
Enter fullscreen mode Exit fullscreen mode

ပြီးရင်တော့ mariadb ကို ချိတ်ဖို့ configuration တွေကို application.properties မှာ အောက်ပါအတိုင်း setting ချပေးပါ။ အခုချိန်ကစပြီး ကျွန်တော်တို့ H2 database အစား MariaDB ကို စသုံးတော့မှာဖြစ်ပါတယ်။

spring.datasource.url=jdbc:mariadb://localhost:3306/cardb
spring.datasource.username=root
spring.datasource.password=YOUR_PASSWORD
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
Enter fullscreen mode Exit fullscreen mode

Spring boot application ကို run လိုက်မယ်ဆိုရင် mariadb ထဲက cardb database ထဲမှာ table တွေ သူ့အလိုလို create လုပ်သွားတာကို တွေ့ရပါလိမ့်မယ်။ JPA ရဲ့ @Entity notation ပါတဲ့ class တွေအတိုင်း table တွေဆောက်သွားတာပါ။

Image description

Oldest comments (0)