intellij idea 14.1 gradle 搭建 spring boot 1.2.5

第一步,创建gradle项目

File -> New -> Project -> Gradle

第二步,配置build.gradle

group 'admin'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'spring-boot'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile("org.springframework.boot:spring-boot-starter-web:1.2.5.RELEASE")
}

第三步,创建spring boot示例

package com;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

/**
 * Created by admin on 2015/8/2.
 */
@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String getSample() {
        return "Hello World!";
    }

    @RequestMapping("/param")
    @ResponseBody
    String getSample(@RequestParam String str) {
        return "Hello World!" + str;
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}


右键 -> Run 'SampleController'

访问:http://localhost:8080/ 显示Hello World!

访问:http://localhost:8080/param?str=admin 显示Hello World!admin


你可能感兴趣的:(intellij idea 14.1 gradle 搭建 spring boot 1.2.5)