赞
踩
参考大佬写的教程===》1、入门环境搭建教程
代码已上传至码云
多次遇见报错
报的第一个错误信息:

默认的是jdk11
但是我用的jdk是1.8的版本,所以这里要修改成8的版本,写成8或者1.8都可以

运行成功:

接着添加Web模块
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
然后添加一个controller,
package com.lyh.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
//@RestController的意思就是controller里面的方法都以json格式输出,不用再写什么jackjson配置的了!
public class HelloWorldController {
@RequestMapping("/helloWorld")
public String helloWorld(){
return "HelloWorld";
}
}
controller的位置:

代码是有问题的,会报错
访问http://localhost:8080/hello报错
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Jan 15 14:47:11 CST 2021
There was an unexpected error (type=Not Found, status=404).
在网上百度了老半天,终于解决问题@ ==>
感谢这位坐着作者
改成这样子就可以了,import包要自己导入一下
package com.example.demo.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWcx { @GetMapping("/hellowcx") @ResponseBody public String hellowcx(){ return "Hello Wcx"; } }
作者还介绍了单元测试,先跳过去
over
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。