随笔 - 68  文章 - 0 评论 - 0 阅读 - 15123
< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10

创建文件夹restdemo 算是project名

在restdemo创建文件夹\src\main\java\hello

在restdemo 创建 build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-rest-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("junit:junit")
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

切换到\src\main\java\hello 文件下

创建Greeting.java

package hello;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}

创建Controller类GreetingController

package hello;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }
}

创建springboot启动类Application.java

package hello;

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

@SpringBootApplication
public class Application {

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

目前restdemo目录下为

cmd进入命令行 :切换到restdemo目录下 输入 gradle build 之后

将工程导入到sts中

打开Application.java ,右击-->run as --> 1java application

在浏览器输入http://localhost:8080/greeting后 在页面显示

{"id":1,"content":"Hello, World!"}
地址换为 http://localhost:8080/greeting?name=roodemo 页面显示
{"id":2,"content":"Hello, roodemo!"}
spring官网的栗子,官网:https://spring.io/guides/gs/rest-service/

看起来就是一般的springmvc啊,没看出来哪里不同了
posted @ 2015-11-10 23:46 xxyyjj 阅读(507) 评论(0) 推荐(0)
摘要: 一直都不对刚开始想可能是字符类型的错,结果删到最后,发现是{}create table xxx() 阅读全文
posted @ 2015-03-05 00:17 xxyyjj 阅读(215) 评论(0) 推荐(0)
摘要: mysql> select * from tb;+------+-------+| id | name |+------+-------+| 1 | tbone || 3 | 2d2 || 5 | 55 || 6 | 66 |+------+------... 阅读全文
posted @ 2014-09-16 02:25 xxyyjj 阅读(128) 评论(0) 推荐(0)
摘要: mysql> insert into tb values (6,'66') -> ;mysql> select * from tb;+------+------+| id | name |+------+------+| 2 | 22 |+------+------+1 row in set (0.... 阅读全文
posted @ 2014-09-16 02:23 xxyyjj 阅读(459) 评论(0) 推荐(0)
摘要: root@mysqlproxy-Compaq:~# mysql -uhpproxy -p1234 -P4040 -h 192.168.19.110mysql> show databases;+--------------------+| Database |+--------------------... 阅读全文
posted @ 2014-09-16 02:17 xxyyjj 阅读(201) 评论(0) 推荐(0)
摘要: ps -A|grep mysqlblog.csdn.net/lmss82/article/details/4414178 阅读全文
posted @ 2014-09-15 14:30 xxyyjj 阅读(496) 评论(0) 推荐(0)
摘要: 做法:下载tomcat插件http://www.eclipsetotale.com/tomcatPlugin.html#A3新解压后放到Eclipse的F:\eclipse\plugins目录下再重启新的不行就用老的 阅读全文
posted @ 2014-09-15 00:16 xxyyjj 阅读(147) 评论(0) 推荐(0)
摘要: 1,ubuntu mysql 默认区分大小写。让他不区分,就在my.cnf中设置lower_case_table_names=1设置后重启mysql 发现没有起作用。mysql> show variables like 'lower_case_table_names' ;+-------------... 阅读全文
posted @ 2014-09-12 11:25 xxyyjj 阅读(543) 评论(0) 推荐(0)
摘要: show master status;之后为空原因1:mysql>show variables like '%log_bin%'; 阅读全文
posted @ 2014-09-12 01:10 xxyyjj 阅读(139) 评论(0) 推荐(0)
摘要: 修噶my.cnf正好在另外一台机器有个相同安装的 阅读全文
posted @ 2014-09-12 00:24 xxyyjj 阅读(836) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示