Spring学习之boot(1)

Spring boot 可以提升开发效率简化spring.xml配置文件首先是一个helloworld 小例子:

package web.app.test.boot;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration
public class TestController {
	
	public final String temp = "Hello,%s";
	
	public final AtomicLong a1 = new AtomicLong();
	@RequestMapping("/test")
	@ResponseBody
	Animal home(String name){
		return new Animal((int) a1.incrementAndGet(),String.format(temp, name));
	}
	
	public static void main(String[] args) {
		SpringApplication.run(TestController.class, args);
	}
}
实体类就不往上写了  Animal  属性 id  name 

下面是maven pom.xml的配置

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
此时直接右键run as 就能跑了

启动成功可以用  http://localhost:8080/test?name=world  地址测试了;

PS:1、一定注意要是Maven的web项目(web.xml完全不用配置)

        2、修改代码后一定要先停服务在启动。(好像也可以配置成修改代码后自动重启的,可以百度下)

        3、也可参照官网http://projects.spring.io/spring-boot/


不忘初心,方得始终!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值