SpringBoot入门案例——创建maven Module方式


最近看到一个大牛写的spring boot案例,链接贴这 https://github.com/ityouknow/spring-boot-examples.git

这里通过在maven里创建多个module的方式实现不同的demo案例,具体步骤如下:

  1. File -> New -> Project直接点击Next

  1. 输入GroupId和ArtifactId

  1. 新建完项目后,将src目录删除,在pom文件里添加build

  1. 右击项目名,New -> Module,与第1步一样,直接点击Next,输入ArtifactId

  1. 新建完module后,打开pom文件,将parent改为spring-boot-starter-parent,添加spring-boot-starter-web

  1. 至此,项目框架已经搭好,开始写代码啦!在spring-boot-hellworld Module下新建相关文件

  1. 代码内容
    HelloWorldController.class
package com.bw.spring.controller;

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

/**
* @DESC
* @AUTHOR wangbing
* @DATE 2019-04-26
*/
@RestController
public class HelloWorldController {

    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }
}

Application.class

package com.bw.spring;

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

/**
* @DESC 访问http://localhost:8080/hello页面
* @AUTHOR wangbing
* @DATE 2019-04-26
*/
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        System.out.println("开始");
        SpringApplication.run(Application.class, args);
    }
}
application.properties文件为空


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM