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

访问网页的方式输出语句

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

访问网页的方式输出语句

访问网页的方式输出语句:

步骤:

  1. 添加springboot起步依赖
    新建一个Maven项目,选择检查jdk1.8的版本 ,命名

    2.创建成功后检查本地仓库是否有东西在下载,在pom.xml中添加

       spring-boot-starter-parent
       org.springframework.boot
       2.4.1
   

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

之后点下刷新,加载依赖。
3.在Java中新建一个类:com.softeem.controller.UserController
4.在UserController中新建一个方法,public String hello
在顶部加@RestController,另外在方法上加 @RequestMapping(“hello”)

package com.softeem.controller;

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

@RestController
public class UserController {
    @RequestMapping("hello")
    public String hello(){
        return "hello world";
    }
}

5.在com.softeem包下面新建一个测试类App,在类上面加@SpringBootApplication

package com.softeem;

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

@SpringBootApplication
public class App {
    public static void main(String[] args) {
      SpringApplication.run(App.class);
    }
}

6.启动类,在网页上输入http://localhost:8080/hello,就可以在网页上访问到打印输出的语句。

注:项目结构如图

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

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

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