1.选择创建方式
2.项目名
3.选择项目依赖
4. 添加webapp目录
添加web依赖(选web依赖后会自动添加,不用再添加)
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
application.properties文件配置
注意端口不能冲突
#配置端口号 项目名
server.port=8080
server.servlet.context-path=/springbootdemo
写个测试的controller
/** * @(#)WebTest.java, 2020/7/27. * <p/> * Copyright 2020 Netease, Inc. All rights reserved. * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.lhh.springbootdemo.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; /** * @author lvhouhou(lvhouhou @ 163.com) */ @RestController public class WebTest { @RequestMapping("hello") public String getHello(){ return "Hello"; } }
启动项目
浏览器访问
OK