博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring boot入门demo
阅读量:4623 次
发布时间:2019-06-09

本文共 4215 字,大约阅读时间需要 14 分钟。

pom.xml

4.0.0
com.example
demo
0.0.1-SNAPSHOT
war
demo
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.5.8.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-maven-plugin
true

项目文件目录

项目文件目录

模拟控制层代码

package com.example.controller;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.example.pojo.Student;/** * spring boot demo * @author XSWL pengfei.xiong * @date 2017年11月17日 */@RestController //相当于@Controller和@RequestBody 返回json@EnableAutoConfigurationpublic class HelloSpringBoot {
@RequestMapping("/hello") public String showHello(){ return "Hello SpringBoot!"; } @RequestMapping("/pojo") public Student showStudent(){ Student student = new Student(1, "show", 20); return student; } @RequestMapping("/map") public Map
showMap(){ Map
map = new HashMap
(); map.put("username", "张无忌"); map.put("age", 15); return map; } @RequestMapping("/list") public List
showList(){ List
list = new ArrayList
(); Student student01 = new Student(1, "show", 20); Student student02 = new Student(1, "show", 20); list.add(student01); list.add(student02); return list; }}

如果对于上面的注解有疑问就看下这个博客:

实体类 就不用说了啊

package com.example.pojo;import java.io.Serializable;public class Student implements Serializable{
private int id; private String name; private int age; public Student() { super(); } public Student(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }}

最后是程序的入口

package com.example.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import com.example.controller.HelloSpringBoot;@SpringBootApplicationpublic class DemoApplication{
// 项目入口 public static void main(String[] args) { SpringApplication.run(HelloSpringBoot.class, args); //运行之后在浏览器中访问:http://localhost:11086/hello 默认端口8080,我这是修改后的路径 }}

补充下:修改端口在application.properties文件中加一句话: server.port=11086

demo源码下载
整合mybatis三层文章 :

转载于:https://www.cnblogs.com/xpf1009/p/9227299.html

你可能感兴趣的文章
JPA 已作废的SQLQuery.class、setResultTransformer方法替换
查看>>
20190402——第一场UPC团队训练
查看>>
爱奇艺视频广告拦截失败,发文共商大计
查看>>
Codeforces 762B USB vs. PS/2 贪心
查看>>
Codeforces Round #394 (Div. 2) 颓废记
查看>>
1003 我要通过! (20 分)
查看>>
洛谷1144 最短路计数
查看>>
BZOJ 1207: [HNOI2004]打鼹鼠
查看>>
堆排序
查看>>
android下网络通信流程
查看>>
Spring+shiro session与线程池的坑
查看>>
Oracle学习笔记(三)----SQL基础
查看>>
【DotNetfans跨平台】谈一谈dotnet-cli开源社区的产品持续集成
查看>>
python入门第十九天 __name__=='__man__'
查看>>
java项目获取路径
查看>>
【转】win7 64位配置bundler-v0.4-source
查看>>
W3C定义的盒模式
查看>>
Python基础学习笔记02之list
查看>>
jquery实现拖拽的效果
查看>>
JS 获取图片标签和所有的图片中的src的正则表达式
查看>>