方式一,利用开发工具搭建
new project,选择Spring Initializr,直接next就行了
如果用国外的网站,提示超时无法创建项目时可以换成阿里的镜像源,https://start.aliyun.com/。
然后选择自己项目所需架包,我这里选了三个,这样项目就建好了。
2、方式二,手动加开发工具
直接选中Maven然后next
新建bean、controller、dao、service package分别用于存放实体对象,控制层,数据访问层和业务层。
在resourse文件夹下,新建mapper文件夹存放映射文件,新建static文件夹存放静态页面,新建templates文件夹存放动态页面。还可以在resource新建配置文件application.yml或application.properties。以yml类型文件为例,配置如下。
运行一个hello world程序
在控制层新建一个HelloSpringboot类
package com.zr.controller;
import com.zr.bean.User;
import com.zr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@ResponseBody
@RequestMapping("hello")
public class HelloSpringboot {
@RequestMapping("s")
public String hello(){
return "hello springboot";
}
}
运行springbootapplication,右键 run spingbootapplication
运行效果
代码上传到了github