springBoot入门笔记
来源:互联网 发布:淘宝无线流量来源 编辑:程序博客网 时间:2024/05/29 09:08
项目目录结构:
com +- xx +- Application.java | +- controller | +- SimpleController .java | +- entity +- User.java
1. Eclipse创建一个简单的Maven工程:
2.修改pop.xml
把下面代码添加进去
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.1.RELEASE</version> </parent> <dependencies><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency> </dependencies>3.实体类
package com.xx.entity;public class User {private int id;private String name;public User() {}public User(int id, String name) {this.id = id;this.name = name;}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;}}
4.Controller类
package com.xx.controller;import org.springframework.web.bind.annotation.*;import com.xx.entity.User;@RestControllerpublic class SimpleController {@RequestMapping("/hello")String hello() {return "Hello World!";}@RequestMapping("/user/{id}")User user(@PathVariable("id") int id) {User user = new User(id, "yourName");return user;}}
5.Application类
package com.xx;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@ComponentScan@EnableAutoConfigurationpublic class Application {public static void main(String[] args) throws Exception { SpringApplication.run(Application.class); }}
6.Spring Boot建议将我们main方法所在的主要的配置类配置在根包名下。
在这个工程里“main方法所在的主要的配置类”为Application类。(见顶部目录图)
0 0
- springBoot入门笔记
- springboot心得笔记-入门
- springboot[入门笔记]
- SpringBoot学习笔记 入门
- SpringBoot入门
- springboot入门
- springboot 入门
- springboot 入门
- SpringBoot入门
- SpringBoot入门
- SpringBoot入门
- Springboot入门
- springboot入门
- SpringBoot入门
- SpringBOOT入门
- SpringBoot 入门
- springboot入门
- SpringBoot入门
- 方法内部调用接口
- matlab一次读取多张图片
- Java-6-解决报错:Java.util.ConcurrentModificationException
- 以生态电商为例,谈电商行业该如何抓准用户心理
- UI学习笔记(一)
- springBoot入门笔记
- C. PolandBall and Forest----并查集水题
- 算法训练 区间k大数查询
- 【web容器】Tomcat Connector的三种运行模式
- springMVC源码分析--HttpMessageConverter参数read操作(二)
- JDBC的事务处理
- 安卓ContentObserver实现验证码自动补全
- Vlan通信原理
- PAT-A 1011. World Cup Betting (20)