springboot创建demo例子

2025-10-28 03:34:45

1、springboot搭建完了之后,可以先大致了解一下。

pom.xml这个里面放了我们很多的配置,比如mybatis和MySQL等等,可以了解一下

springboot创建demo例子

2、application.properties这个文件可以存放我们连接数据的一些配置,还可以映射一些重要的文件,如图

下面的mybatis-config.xml可以先删掉

springboot创建demo例子

3、DemoApplication这个类就是我们的启动类,以后启动springboot就可以使用

springboot创建demo例子

4、可以把下面代码复制粘贴到我们的启动类

package com.example.demo;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.stereotype.Controller;

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

import org.springframework.web.bind.annotation.ResponseBody;

@Controller

@SpringBootApplication

public class DemoApplication {

    @RequestMapping("/hello")

    @ResponseBody

    String home() {

        return "Hello ,spring boot!";

    }

public static void main(String[] args) {

SpringApplication.run(DemoApplication.class, args);

}

}

springboot创建demo例子

5、右击Run As,选择springboot启动

springboot创建demo例子

6、启动成功

springboot创建demo例子

7、在浏览器输入http://localhost:8080/hello

然后看到运行结果!

springboot创建demo例子

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢