单模块搭建
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工程包会自动生成启动类
待整理……