国产探花免费观看_亚洲丰满少妇自慰呻吟_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類。(見頂部目錄圖)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高唐县| 南皮县| 龙南县| 江都市| 日照市| 南昌县| 定远县| 石嘴山市| 凌云县| 连山| 凤城市| 武山县| 桑日县| 辛集市| 平果县| 武威市| 宁明县| 甘洛县| 安义县| 元氏县| 柳林县| 峡江县| 仙游县| 河池市| 广饶县| 二连浩特市| 阿瓦提县| 资阳市| 聊城市| 大新县| 吉林省| 富锦市| 万年县| 双峰县| 乃东县| 贵州省| 凌海市| 桦甸市| 滨海县| 化德县| 云霄县|