dyc87112 / blog-comments

5 stars 1 forks source link

Spring Boot开发Web应用 | 程序猿DD #328

Open dyc87112 opened 5 years ago

dyc87112 commented 5 years ago

http://blog.didispace.com/springbootweb/

Spring Boot快速入门中我们完成了一个简单的RESTful Service,体验了快速开发的特性。在留言中也有朋友提到如何把处理结果渲染到页面上。那么本篇就在上篇基础上介绍一下如何进行Web应用的开发。 静态资源访问在我们开发Web应用的时候,需要引用大量的js、css、图片等静态资源。 默认配置Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下

superoery commented 5 years ago

由于从第一个教程跟到现在这个教程,我的HelloController文件里,类前面的注释为@RestController而不是@Controller。测试的时候发现页面显示的东西是“index”,改成@Controller才能正常显示为“http://blog.didispace.com”。 原因是@RestController注解相当于@ResponseBody+@Controller合在一起的作用。 @ResponseBody可以用来返回JSON @Controller在对应的方法上,视图解析器可以解析return 的jsp,html页面 但是如果只是使用@RestController注解Controller,则Controller中的方法无法返回jsp页面,或者html,配置的视图解析器 InternalResourceViewResolver不起作用,返回的内容就是Return 里的内容。因此显示的内容是HelloController的返回值“Index”

superoery commented 5 years ago

参考链接:https://www.cnblogs.com/shuaifing/p/8119664.html

caidapao commented 5 years ago

hello didi:

Thymeleaf的默认参数配置的配置文件中,最后一行代码没有换行导致spring.thymeleaf.suffix=.html配置不生效。有空可以改一下

daniumqy commented 5 years ago

<h1 th:text="${host}">报红

解决方案:将html改为<html lang="en" xmlns:th="http://www.thymeleaf.org">

2110483505 commented 4 years ago

我也不知道你这个代码怎么跑成功的