您的位置:首页 > 编程语言 > Java开发

创建一个简单的springboot项目,实现restful接口

2019-01-18 11:19 821 查看

 

首先new一个project

点击next继续,

next继续

next继续,

点击finish,创建完成

点击运行,出现如下结果:

这是因为缺少数据库的参数配置导致,继续添加数据库参数配置。

application.properties 改为application.yml,可以不改,视个人喜好而定。

[code]spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/boot_backend?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
username: root1
password: root1
druid:
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: true
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,wall
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
stat-view-servlet:
allow: 127.0.0.1

参数错误没关系,只要有配置,springboot就可以读取到配置,不会报错。

再次启动服务,成功!

创建类TestController.java

[code]package com.liuxy.nes3.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

@RequestMapping(value = "/test",method = RequestMethod.GET)
public String hello() {
return "test the new spring boot!";
}
}

再次启动服务,浏览器输入http://localhost:8080/test

 

 

 

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: