国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

springBoot入門筆記

2019-11-08 18:31:17
字體:
來源:轉載
供稿:網友

項目目錄結構:

com     +- xx         +- application.java         |         +- controller         |   +- SimpleController .java         |         +- entity             +- User.java

1. Eclipse創建一個簡單的Maven工程:

com +- example     +- myPRoject         +- Application.java         |         +- domain         |   +- Customer.java         |   +- CustomerRepository.java         |         +- service         |   +- CustomerService.java         |         +- web             +- CustomerController.java

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類。(見頂部目錄圖)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张家港市| 左云县| 金秀| 宜章县| 垫江县| 宁武县| 周宁县| 东乡县| 达尔| 墨脱县| 柳州市| 巴东县| 昌图县| 舟曲县| 盖州市| 蓝田县| 宜川县| 台北县| 来凤县| 修文县| 望都县| 鄂尔多斯市| 双柏县| 布尔津县| 兴化市| 乌兰察布市| 徐闻县| 苍溪县| 荥经县| 龙山县| 湘乡市| 无锡市| 嘉义市| 平阴县| 中阳县| 从江县| 镇巴县| 伊吾县| 商都县| 额尔古纳市| 甘孜县|