创建一个简单的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
相关文章推荐
- 【Spring Boot && Spring Cloud系列】构建Springboot项目 实现restful风格接口
- 使用CXF+spring+restful创建一个web的接口项目
- 使用CXF+spring+restful创建一个web的接口项目
- SprigBoot(三)创建一个简单的SpringBootWeb项目
- Idea简单创建一个springboot的maven项目
- 使用Gradle创建一个最简单的Spring Boot项目
- SpringBoot——创建一个简单的SpringBoot项目
- Spring Boot创建一个简单项目
- SpringBoot IntelliJ创建简单的Restful接口
- IDEA-------(二)快速创建一个简单的Spring boot项目
- SpringBoot2.0学习之创建一个简单的web项目
- 使用IDEA创建一个简单的基于Spring Boot的RESTful Web Service
- 采用CXF+spring+restful创建一个web接口项目
- 创建一个简单的Spring Boot项目
- 使用CXF+spring+restful创建一个web的接口项目
- SPRING INITIALIZR创建一个简单的SpringBoot项目(https://start.spring.io/)
- 使用CXF+spring+restful创建一个web的接口项目
- STS创建Spring Boot项目实战(Rest接口、数据库、用户认证、分布式Token JWT、Redis操作、日志和统一异常处理)