栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot整合SpringMVC - 001 - helloworld

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot整合SpringMVC - 001 - helloworld

文章目录
  • 一、创建父工程
    • 1.1 创建maven工程
    • 1.2 修改pom.xml文件
  • 二、HelloWorld
    • 2.1 创建子工程(_001.helloworld)
    • 2.2 子工程结构
    • 2.3 TestController
    • 2.4 启动类 SpringMvcApplication
    • 2.5 运行 SpringMvcApplication

一、创建父工程 1.1 创建maven工程

创建一个普通的maven工程boot-springmvc-test,把工程里面的其他内容都删掉,只保留.idea和pom.xml。如下图:

1.2 修改pom.xml文件


    4.0.0
    pom
    
        _001.helloworld
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.6
         
    
    prv.dongruan
    springmvc
    1.0-SNAPSHOT

    
        11
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

二、HelloWorld 2.1 创建子工程(_001.helloworld)

2.2 子工程结构

2.3 TestController
package prv.dongruan.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    @GetMapping
    public String sayHello() {
        return "hello world";
    }
}
2.4 启动类 SpringMvcApplication

特别说明:启动类不能和TestController在同一层目录,必须在它的父目录里面

package prv.dongruan;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringMvcApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringMvcApplication.class);
    }
}
2.5 运行 SpringMvcApplication

运行成功后。即可通过 http://localhost:8080/test 访问 TestController

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/530744.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号