2、spirngBoot快速上手

这一篇博客说一下springBoot的helloWorld如何写,也就是如何利用springBoot写一个web服务器。想想还是蛮厉害的一点点配置就实现了一个socket服务器加上一个http服务。

  1. idea新建工程,选择spring initializer 创建springboot应用,server url 设置为
https://start.aliyun.com/

spring boot 版本随便选择 2 或者3,project SDK选择1.8,java Version 选择8,创建好了之后在src.main.java.com.helloSpring 新建controller文件夹,在controller文件夹中新建HelloController.java里面填写代码:

package com.example.hellospring.controller;

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


public class HelloController {
    (value= "/hello", method = RequestMethod.GET)
    public String index(){

        return "i m fine  and you ?";
    }
}

在src.main.resource之中可以通过修改 server.port = 8081将访问端口设置为8081。

server.port = 17003
spring.devtools.restart.enabled=true
spring.devtools.restart.additional-paths=src/main/java
spring.devtools.restart.exclude=static/**

设置好后,启动项目在服务器中输入http:/localhost/17003/hello 就可以访问到 这个写好的页面了,哈哈哈哈。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值