Self-learing project for Springboot for RESTful API with SQLite database
Go to file
2023-12-21 23:51:44 +08:00
.mvn/wrapper First commit with code 2023-12-19 11:19:08 +08:00
data First commit with code 2023-12-19 11:19:08 +08:00
src Add init db and sample data 2023-12-21 23:51:44 +08:00
.gitignore First commit with code 2023-12-19 11:19:08 +08:00
mvnw First commit with code 2023-12-19 11:19:08 +08:00
mvnw.cmd First commit with code 2023-12-19 11:19:08 +08:00
openapi.yml Refactor 2023-12-21 19:05:45 +08:00
pom.xml Refactor 2023-12-21 19:05:45 +08:00
README.md Refactor 2023-12-21 19:05:45 +08:00

Project for learning Spring Boot, RESTful API, and SQLite

This is a self-learing project for Spring Boot for RESTful API with SQLite database

Environments

The following tools/libraries are used in this project:

  1. Microsoft VS Code
  2. OpenJDK 17
  3. VSCode extensions:
    1. Debugger for Java
    2. Extension Pack for Java
    3. Java Code Generators
    4. Language Support for Java(TM) by Red Hat
    5. Maven for Java
    6. Project Manager for Java
    7. Spring Boot Dashboard
    8. Spring Boot Extension Pack
    9. Spring Boot Tools
    10. Spring Initializr Java Support
    11. SQLite (Optional)
    12. Test Runner for Java (Optional)
  4. Linux or Windows WSL2 with Bash or Zsh Shell
  5. Linux Package
    1. sqlite3

Create the project from scratch

The following steps will create this project from scratch. Assuming the environment has been setup properly.

Create Spring Boot Project in VSCode

  1. Start VSCode (e.g. from CLI: code .) and open the project folder
  2. Press CTRL-SHIFT-P and type Spring Initializr
  3. Select Spring Initializr: Create a Maven Project...
    1. Specify Spring Boot Version: 3.2.0
    2. Specify project language: Java
    3. Input Group Id: com.example (or any other you like)
    4. Input Artifact Id: demo (or any other you like, it will be the project folder too.)
    5. Specify packaging type: Jar
    6. Specify Java version: 17
    7. Choose dependencies:
      1. Spring Web
      2. Spring Boot DevTools
      3. MyBatis Framework
    8. Select the directory for file generation (NOTE: Project folder will be created under this folder)
  4. Now the project layout (needed files and folders) should be created.
  5. A dialogue will be prompted for opening the new project in VSCode. You can also Restart the VSCode under the generated project folder directly

Add Maven dependencies

  1. In VSCode Explorer, expand Maven panel and locate the Dependencies
  2. Click the + button next to the Dependencies dropdown item
  3. Type sqlite-jdbc, press ENTER, and find sqlite-jdbc org.xerial, Select it
  4. Type gson, press ENTER, and find gson com.google.code.gson, Select it
  5. New dependence will be downloaded and added

Update the Maven/Project information (Optional)

  1. Open poe.xml

  2. Change the <groupId>,<artifactId>,<name>,<description> for your desire

  3. Use VSCode to renew (refactor) the folder and file accordingly

    - src
        |-main
            |- java/com/example/demo --> java/{other group}/{other id}
                |- DemoApplication.java -<RENAME>-> MainApplication.java
    
    (Note: VSCode will modify the java file accordingly)
    
    

Create/Update the folders or files

- data <NEW>
- src
    |-main
        |-java/com/example/demo (or other folder)
            |- model <NEW>
            |- ApiController.java <NEW>
        |-resources
            |- mapper <NEW>
                |- mainapp.xml <NEW>
            |- mybatis <NEW>
                |- mybatis-config.xml <NEW>

Update/Create the files

Refer to the file in this project, update the following files accordingly:

Init the database and insert sample data

Please see the README for Data folder file

Start Spring Boot Application

To start this Spring Boot Application:

  1. Open VSCode
  2. Select Spring Boot Dashboard (Left Toolbar)
  3. Rollover the APPS dropdown, click |>> button

TODO

  1. Resolve WARN "MyBatis: No MyBatis mapper was found in '[xx.mapper]' package. Please check your configuration."
  2. Why application.properties - spring.datasource.url is requried even the mybatis config exist
    1. what should be the correct value? jdbc:sqlite:data or jdbc:sqlite:data:abc ok ,but jdbc:sqlite not ok.
  3. In src/main/java/com/example/demo/ApiController.java
    1. See the TODO
    2. Rewrite the controller code better