SpringBoot·Web项目单模块与多模块搭建

SpringBoot·Web项目单模块与多模块搭建

单模块搭建

1.new project选择spring initializr
groupld:   com.debug.steadyjack   // 这个就是建立的项目src.main.java下的层级目录包
arifactid: springboot_muultipart  // ArtifactID就是项目的唯一的标识符

选择下一步
project name: springboot_multipart //项目名称
project location:                  //项目存放路径地址
选择fnish完成

构建单模块项目

1.controller 包
.HelloWorldController.class
2.entity 包
3.service 包

–简单的helloworld
–HelloWorldController.class

package com.debug.steadyjack.controllrer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping(value = "/helloworld",method = RequestMethod.GET)
    public String sayHello(String name)
    {
        return String.format(("hello: %s") ,name);
    }
}

#访问url
#参数传参
http://localhost:8080/helloworld/name=111


sercer.port=9099
#server.context-path=/single/sb #此设置在springboot2.0以后,这个配置已被废除
server.servlet.context-path=/single/sb
#访问url
http://localhost:9099/helloworld/ // 原来应访问路径
http://localhost:9099/single/sb/helloworld/ // 配置server.servlet.context-path后访问路径

--entity
--User.class  
package com.debug.steadyjack.entity;
import java.io.Serializable;
public class User implements Serializable {

    private Integer id ;
    private String name ;

    public Integer getId() {
        return id;
    }
    //构造方法
    public User(Integer id, String name) { 
        this.id = id;
        this.name = name;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

–HelloWorldController.class

package com.debug.steadyjack.controllrer;
import com.debug.steadyjack.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @RequestMapping(value = "/helloworld",method = RequestMethod.GET)
    public User sayHello()
    {
        return new User(1,"debug");
    }
}

构建多模块项目

父模块   
	子模块-api: 1.面向其他服配置-比如发布成Dubbo服务的接口配置等就都在这里
				2.会将整个项目中所有子模块的依赖放在这里配置-从而被传递性的依赖即可

	子模块-model: 1.面向ORM-数据访问控制层次

	子模块-server: 1.打包成可执行的jar、war等配置
				   2.SpringBoot应用的启动类
				   3.整个项目/服务的核心开发逻辑所在
新建一个项目:
父模块-新建maven项目:
			1. Groupld: com.debug.steadyjack
			2. Artifactld: springboot_multipart
			3. version: 1.0.1
			新建好后父模块的src可以删除不要(因在父模块src中不做什么处理)
在父项目下建立子模块: 选中父项目新建model选maven新建
子模块-新建model: 1. Artifactld: api
子模块-新建model: 1. Artifactld: model
子模块-新建model: 1. Artifactld: server

然后在server层main.java下建com.debug.steadyjack.server包

注:新建的maven工程下没有启动类,只是建立了一个框架包,所有的类与依赖需要手动配置 ,spring initializr工程包会自动生成启动类

待整理……

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青鸟遇鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值