实习第一天,leader让我先熟悉springboot,自己创建个项目,找到教程之后开干,结果不断遇坑
参考(23条消息) maven卸载安装(最全详细及简明教程)_你还不是会员哦的博客-CSDN博客_卸载mavenhttps://blog.csdn.net/m0_59119256/article/details/121851306?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-121851306-blog-124162719.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-121851306-blog-124162719.nonecase&utm_relevant_index=1建议本地仓库和maven放在一个文件夹里,这样卸载的时候方便
参考(21条消息) 如何创建springboot项目_H `K的博客-CSDN博客_创建springboot项目https://blog.csdn.net/wshjk/article/details/123879847
Artifact Coordinates左边有个小箭头,点击后可以设置ArtifactId
需要配置为2.2.6.RELEASE
本来以为完成maven配置后一劳永逸了,结果每新建一个项目都会变为默认配置
一劳永逸的方法:
File --> New Projects Settings --> Settings for New Projects
更改新项目的默认配置
按提示找到报错的行,删除多余空格,用VS CODE打开能看到黄色的多余空格
第二步没有改id,导致定位坐标有问题
Circular view path [readingList]: would dispatch back to the current handler URL [/readingList] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.
参考SpringBoot 报错: Circular view path [readingList] 解决办法 - 等不到的口琴 - 博客园 (cnblogs.com)https://www.cnblogs.com/Courage129/p/12674748.html
原因:thymeleaf依赖有问题,相当于没有声明ViewResolver,spring会注册一个默认的ViewResolver, 它将model对象作为request请求的属性值暴露出来, 并将该请求通过javax.servlet.RequestDispatcher转发到指定的URL,但在Spring中这个view的URL是可以RequestDispatcher转发的。相当于请求通过RequestDispatcher转发到URL,RequestDispatcher又会转发URL,不停地自己转发自己,陷入死循环
教程中引入thymeleaf依赖用的是org.thymeleaf和org.thymeleaf.extras,换成org.springframework.boot中的spring-boot-starter-thymeleaf问题解决
用Spring initializr创建springboot项目生成的依赖配置中也是使用的spring-boot-starter-thymeleaf,org.thymeleaf和org.thymeleaf.extras好像适用于Spring,我目前没找到为什么用org.thymeleaf和org.thymeleaf.extras会报错
使用thymeleaf可能需要配置application.properties
(25条消息) spring-boot-starter-thymeleaf 避坑_Swanyf的博客-CSDN博客https://blog.csdn.net/qq_40322118/article/details/90667552
SpringApplication.run(类名.class,args);
启动类里的类名写错了
网上说出现这个错的原因有可能是Springboot和SpringCloud版本冲突,但我只是创建了Springboot,如果有出错项目中用SpringCloud的朋友可以考虑这个问题
公司项目用的springboot版本是2.2.6,但我用Spring initializr创建springboot项目时,最低能选的版本就是2.6.8,后来查到idea只能选择一些新的版本,需要手动降版本
参考(22条消息) 【SpringBoot 笔记】SpringBoot版本降级_「已注销」的博客-CSDN博客_idea降低springboot版本https://blog.csdn.net/b5ckorg/article/details/104219642?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-104219642-blog-107829859.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-104219642-blog-107829859.pc_relevant_aa&utm_relevant_index=1
修改完版本并导入完成后要记得恢复单元测试的dependency再导入一次
创建结束后,发现无法新建包和类,maven中只有Lifecycle,查到是因为maven与idea版本不兼容,我的idea是2020.1,支持3.6.3及以下,但我下maven的时候直接下了最新的3.8.5
查看与哪个版本兼容可以参考(23条消息) IDEA 2018 2020 2021 2022 各版本对Maven版本兼容问题汇总_Resourceful!的博客-CSDN博客_maven和idea版本https://blog.csdn.net/qq_44866828/article/details/117571120?utm_term=maven3.8.5%20%E5%92%8Cidea2020&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-0-117571120-null-null&spm=3001.4430
maven官网下载页面推荐下载最新版,下拉可以找到Previous Releases,点击 archives,找到要找的旧版本,找到binaries里面的文件下载
参考(23条消息) 异常:This application has no explicit mapping for /error, so you are seeing this as a fallback解决方法_渴望飞的鱼的博客-CSDN博客_explicit mappinghttps://blog.csdn.net/qq_36411874/article/details/93486993
一定要在同级目录下新建Controller包,否则识别不到
上面提到的如何创建Springboot项目的教程中,在HelloController类中用的是@Controller,表示运行对应名称的页面,如果想返回页面,return后面跟的应该是页面名称,不能随便写,用@RestController直接返回名称,这是return后面只是一个普通字符串,可以随便定义,也可以把@RestController拆成@Controller和@ResponseBody
文字:
参考(23条消息) Spring boot 自定义banner的在线制作_Java技术干货的博客-CSDN博客https://blog.csdn.net/qq_33399709/article/details/103590318?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-103590318-blog-110510668.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~default-1-103590318-blog-110510668.pc_relevant_aa&utm_relevant_index=1
图片:
参考(23条消息) springboot banner_Meiko丶的博客-CSDN博客_springbootbannerhttps://blog.csdn.net/u010365819/article/details/122574100(23条消息) springboot banner在线生成_SpringBoot 自定义Banner图_weixin_39916758的博客-CSDN博客
https://blog.csdn.net/weixin_39916758/article/details/111575132(23条消息) springboot banner_Meiko丶的博客-CSDN博客_springbootbanner
https://blog.csdn.net/u010365819/article/details/122574100
banner生成网站
关于可达鸭的ascii艺术字,Spring Boot 可达鸭 Banner-bootschool.nethttps://www.bootschool.net/ascii-art/search
我选了宇航员,还挺可爱的