安装vscode with springboot

1、安装jdk8

 

2、下载vscode,一切按照默认配置完成安装。
下载地址:https://code.visualstudio.com

 

3、安装完成后,运行vscode。
如果没有任何反应,在命令行上运行以下命令:
netsh winsock reset
然后重新启动vscode即可。

 

4、安装扩展:
Chinese (Simplified) Language Pack for Visual Studio Code
Java Extension Pack

Spring Initializr Java Support

Spring Boot Extension Pack

XML

 

5、快捷键Ctrl+Shift+P,选择:
Spring Intializer: Generate a maven project.
依次输入:

Specify project language: java
Input GroupId for your project: com.company
Input Artifact Id for your project: demo
Specify Sprint Boot version: 2.1.2
Search for depencencies: DevTools, Web, Thymeleaf

回车确认,保存项目到指定文件夹内。

 

6、打开项目,编辑resources/application.properties:

server.servlet.context-path=/demo

 注意,context-path的值,必须以斜杠开头

 
7、新建文件:com/company/demo/controllers/HomeController.java
package com.company.demo.controllers;

import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String index(HttpServletRequest request) {
        request.setAttribute("project", "Demo Application");
        return "index";
    }
}

 

8、新建文件:resources/templates/index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Home</title>
    </head> 
    <body> 
        Welcome to [[${project}]] !
    </body>
</html>

 

 

9、打开项目,按F5键运行。

 在浏览器中输入:http://localhost:8080/demo/
 
 浏览器应该显示:Welcome to Demo Application !
 
posted @ 2019-01-17 11:16  卡卡西村长  阅读(276)  评论(0编辑  收藏  举报