Spring Boot入门

加粗样式

1.MAVEN的设置

给MAVEN的settings.xml的配置文件profiles标签添加
			<id>jdk1.7</id>    
			<activation>    
				<activeByDefault>true</activeByDefault>    
				<jdk>1.7</jdk>    
			</activation>    
			<properties>    
				<maven.compiler.source>1.7</maven.compiler.source>    
				<maven.compiler.target>1.7</maven.compiler.target>    
				<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>    
			</properties>    
		</profile>  

2.Spring Boot 练习

	浏览器发送请求,服务器接收请求并处理,响应Hello World!字符串
	1,创建一个maven工程(jar)
	2,导入依赖Spring Boot相关的依赖
   <parent>
   	<groupId>org.springframework.boot</groupId>
   	<artifactId>spring-boot-starter-parent</artifactId>
   	<version>1.5.9.RELEASE</version>
   </parent>
   <dependencies>
   	<dependency>
   		<groupId>org.springframework.boot</groupId>
   		<artifactId>spring-boot-starter-web</artifactId>
   	</dependency>
   </dependencies>

3.编写一个主程序;启动Spring Boot应用

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 *@SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用
 */

@SpringBootApplication
public class HelloWorld {

	public static void main(String[] args) {
		// Spring应用启动起来 
		SpringApplication.run(HelloWorld.class, args);
	}

}

4.编写相关的Controller,Service,Dao

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloContrller {
	@RequestMapping("/hello")
	@ResponseBody
	public String hello(){
		return "Hello World!";
	}
}

5.运行主程序

6.简化部署

<!--这个插件, 可以将应用打包成一个可执行的jar包  -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
	```
	将这个应用打成jar包,直接用 java -jar的命令进行执行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值