VisualStudioCode + Java + SpringBoot

VisualStudioCode + Java + SpringBoot

Introduction

What editor do you use for Java development?

Etc. are famous. I myself write Java a lot at work, but the IDE is Eclipse. There are many Pleiades All in One. After all, it is probably because the cost of construction is low because the frequently used ones are pre-installed. However, Eclipse is heavy, isn't it? Especially when it starts up ...

VisualStudioCode

A text editor for Visual Studio provided by Microsoft. It supports not only Windows but also macOS and Linux. I use it a lot these days because it starts up quickly and is light. Although it is a text editor, it is equipped with various plug-ins and debugging functions as standard, and can be used almost like an IDE depending on the plug-ins and settings.

VisualStudioCode + Java + SpringBoot

Such Visual Studio Code can develop various languages. I recently learned that you can also develop Java ... That means that you can use Java environment construction and Spring Boot, so I will leave a memorandum of Spring Boot environment construction.

Download and install Visual Studio Code (win)

It is a Windows environment construction.

-Download at here. --Launch the downloaded VSCodeUserSetup-x64-X.XX.X.exe. --Click "Next>" in "Start Visual Studio Code Setup Wizard". --In "Agreement of License Agreement", check "Agree (A)" and click "Next (N)>". --Specify the installation location in "Specify installation destination". The default is fine, but I tried to make it directly under C. --Click "Next (N)>". --Click "Next (N)>" as it is in "Specify program group". --Select the following in "Select additional tasks".

*In Explorer's File Context Menu[Open with Code]Add an action "
*In the Explorer Directory context menu[Open with Code]Add an action "
*"Register Code as an editor for supported file types"
*"Add to PATH(Available after reboot)」

Choose.

Addition of extension

Add an extension (plug-in) for Visual Studio Code.

--Japanese localization: Japanese Language Pack for Visual Studio Code --Java Development: Java Extension Pack

JDK installation

Install the JDK and add environment variables. (Omitted)

Java: Home settings

--Open the "Settings" window with "Ctrl" + ",". --When you enter "Java: Home" in "Search settings", the following is displayed.

Java: Home
Specifies the folder path to the JDK (8 or more recent) used to launch the Java Language Server.
On Windows, backslashes must be escaped, i.e.
"java.home":"C:\\Program Files\\Java\\jdk1.8.0_161"

Click "Edit with setting.json".

setting.json


{
    "java.home": "C:\\XXXX\\Java\\jdk1.8.0_131"
}

Describe the path (JAVA_HOME) to the place where the JDK is located in setting.json.

This completes the minimum Java development.

Creating a Java project

Let's create a Java project.

--Use "Ctrl" + "Shift" + "P" to display the "Command Palette" and enter the following.

Java: Create Java Project

--Set the directory to be the workspace in "Specify folder".

--Specify the name of the Java project in "Input a java project name".

--A new window will appear showing the project. Inside the project are the bin and src directories, inside which are App.class and App.java.

useful function

--There is Run | Debug above the main method in App.java. Run to run, Debug to debug.

--Breakpoints can be set by clicking on the numbers displayed on the left when focusing on the left to display a red circle.

--Execution argument is debug-> gear icon-> launch.json You can pass execution arguments by adding "args": to the execution configuration.

{
    "configurations": [
        {
            "type": "java",
            "name": "CodeLens (Launch) - App",
            "request": "launch",
            "mainClass": "app.App",
            "projectName": "test_project",
            "args": ""← This
        }
    ]
}

--Code format: "Alt" + "Shift" + "F"

--Using the console

in launch.json

  "console": "integratedTerminal",

To set

SpringBoot

We will add an extension to enable SpringBoot.

--Spring Boot Extension: "Spring Boot Extension Pack" --Lombok Extensions: "Lombok Annotations Support for VS Code"

Spring Boot project

Create a Spring Boot project.

--Open "Command Palette" with "Ctrl" + "Shift" + "P" and enter the following.

Spring Initializr: Generate a Maven Project

--Enter (select) "Java" in Specify project langue age. --Enter "Group ID" in Input Group Id for your project. --Enter "Arifact ID" in Input Arifact Id for your project. --Enter (select) "2.1.6" in Specify Spring Boot version --Select the following in Search for dependencies

* Spring Web Starter
* Spring Boot DevTools
* Lombok
* Thymeleaf
* MySQL Driver
* MyBatis Framework

--Press Selected 6 dependencies

DB settings

--MySQL installation (abbreviation) --Create DB

CREATE DATABASE test_db CHARACTER SET utf8;

--Create table

CREATE TABLE IF NOT EXISTS
member                                              --table name
(
    MAIL_ADDRESS varchar(255) NOT NULL PRIMARY KEY  --Email address: PK
    ,NAME varchar(255) NOT NULL                     --name
    ,CREATED_DATE datetime                          --Registered Date
    ,CREATED_USER varchar(255)                      --Registered person
    ,UPDATED_DATE datetime                          --Update date and time
    ,UPDATED_USER varchar(255)                      --changer
);

--Added DB connection settings to application.properties

application.properties


spring.datasource.url=jdbc:mysql://localhost:3306/test_db
spring.datasource.username=root
spring.datasource.password=

--You can launch the application and access the application with ``` http: // localhost: 8080 /` ``.

MyBatis Generator

I am using MyBatis as an OR mapper. MyBatis has a tool called MyBatis Generator that automatically generates java files from the DB. In Eclipse, I could use it by installing the plug-in. In VisualStudioCode, I thought about what to do.

--Download mybatis-generator

Download and unzip mybatis-generator-core-X.X.X.zip from here.

--Place lib / mybatis-generator-core-X.X.X.jar in the unzipped materials in src / main / resources --Place generatorConfig.xml

Place src / main / resources / generatorConfig.xml

generatorConfig.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
    <!--Path to JDBC driver-->
    <classPathEntry location="/Users/XXX/XXX/mysql/mysql-connector-java/8.0.16/mysql-connector-java-8.0.16.jar"/>
    <context id="local">
        <!--Connection destination DB information-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test_db?useSSL=false&amp;nullCatalogMeansCurrent=true" userId="root"
                        password="" />
        <!-- Model(Entity)Creation destination-->
        <javaModelGenerator targetPackage="xxx.xxx.app.db.entity"
                        targetProject="/Users/XXX/Documents/workspace/xxx/src/main/java" />
        <!-- Mapper.xml creation destination-->
        <sqlMapGenerator targetPackage="xxx.xxx.db.mapper"
                        targetProject="/Users/XXX/Documents/workspace/xxx/src/main/resources" />
        <!-- Mapper.java creation destination-->
        <javaClientGenerator targetPackage="xxx.xxx.db.mapper"
                        targetProject="/Users/XXX/Documents/workspace/xxx/src/main/java"
                        type="XMLMAPPER" />
        <!--Table to be generated-->
        <table schema="test_db" tableName="member" ></table>
    </context>
</generatorConfiguration>

--Start mybatis-generator Start powershell (in VS Code) Go to xxx \ src \ main \ resources and kick the following command

powershell


> java -jar .\mybatis-generator-core-X.X.X.jar -configfile .\generatorConfig.xml -overwrite

Recommended Posts

VisualStudioCode + Java + SpringBoot
[Java] SpringBoot + Doma2 + H2
Java
Java
[Java & SpringBoot] Environment Construction for Mac
Java learning (0)
Studying Java ―― 3
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
[Java] Connection with local DB (IntelliJ + SpringBoot)
java beginner
Java (add2)
JAVA (Map)
[java] interface