springboot返回页面
1、使用@Controller注解:
@Controller必须配合模板
先导入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
由于我项目创建前系统自动在resources下创建了static和templates文件,如果没有,手动创建一个templates文件夹即可,新建一个文件:index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1</title>
</head>
<body>
<p>你好</p> </body>
</html>
在controller中写入方法进行测试:
package com.bonc.datapool.controller; import com.bonc.datapool.domain.Area;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date; /**
* @program: datapool
* @description:
* @author:
* @create: 2018/07/04
*/
@Controller
@RequestMapping("/return")
public class AreaController { @RequestMapping("/a")
public String get(){
return "index";
}
}
使用thymeleaf为了防止缓存可在配置文件中添加:
# 定位模板的目录
spring.mvc.view.prefix=classpath:/templates/
# 给返回的页面添加后缀名
spring.mvc.view.suffix=.html spring.thymeleaf.cash=false
运行程序,出现以下结果:

2、不使用模板返回静态页面
https://blog.csdn.net/u012882134/article/details/77230900/
(1)controller不变,配置文件增加视图解析器:
server.port=8081 logging.level.com.bonc = info
#配置应用名称
spring.application.name=data_druid
#spring.thymeleaf.cache=false
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html
将index页面放入静态文件夹:


(2)如果将静态页面放在templates:

配置文件:
server.port=8081 logging.level.com.bonc = info
#配置应用名称
spring.application.name=data_druid
#spring.thymeleaf.cache=false
spring.mvc.view.prefix=/templates/
spring.mvc.view.suffix=.html

使用ModelAndView没有成功,留待明日解决!
springboot返回页面的更多相关文章
- SpringBoot返回页面乱码解决
SpringBoot,在做全局异常处理的时候,返回中文字符串时,出现乱码情况,网上查阅资料之后,解决方式如下所示,自定义WebConfiguration继承WebMvcConfigurationSup ...
- SpringBoot如何返回页面
SpringBoot中使用Controller和页面的结合能够很好地实现用户的功能及页面数据的传递.但是在返回页面的时候竟然会出现404或者500的错误,我总结了一下如何实现页面的返回以及这里面所包含 ...
- SpringBoot返回html页面
一般Controller返回数据或页面,今天谈一下返回页面的场景. 一.不使用template 1. controller中定义对应的访问路由及返回的页面(使用Controller,不要使用RestC ...
- 优化vue+springboot项目页面响应时间:waiting(TTFB) 及content Download
优化vue+springboot项目页面响应时间:waiting(TTFB) 及content Download TTFB全称Time To First Byte,是指网络请求被发起到从服务器接收到地 ...
- 支付宝通知页面notify_url、返回页面return_url
返回页面(return_url文件)工作原理 即:商户系统请求/支付宝响应交互模式 1. 构造请求数据 商户通过提供的接口代码示例,通过代码示例的规则,程序构造与运算得到sign加密结果以及构造后的 ...
- springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。
问题描述:在我写的主页面中用到了iframe,其中在iframe中有一个button点击提交,然后在Controller中返回页面的时候,是在iframe中打开的,而不是整个页面. 最开始我想用aja ...
- react-router(v4) 路由跳转后返回页面顶部问题
遇到的问题 由A页面跳转到B页面,B页面停留在A页面的位置,没有返回到顶部. 问题分析 首先分析下出现此问题的原因: 在项目中使用的是 hashHistory,它是建立在 history 之上的,当路 ...
- HTML5商城开发五 实现返回页面顶部
本文内容主要是网上参考收集,介绍四种简单的返回页面顶部代码,可以使用简单的HTML锚标记,也可使用Javascript Scroll函数动态返回等等. 一.使用锚标记返回页面顶部 使用HTML锚标记最 ...
- selenium的browser.page_source无法返回页面内容
selenium的browser.page_source无法返回页面内容 可能是编码的问题.. html= (browser.page_source).encode('GBK', 'ignore') ...
随机推荐
- textbox 未
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- Qt QGraphicsItem要点 积累
1.在创建QGraphicsItem子类的时候,想要实现自己绘图,一般是重新实现boundingRect()和paint()函数,如果不重新实现shape(),基类的实现将会退而使用 bounding ...
- 【js】版本号对比处理方案
今天在处理一个bug问题,适配客户端版本:若版本号未达到,则不可运行该功能,若达到则可运行. 版本号规则如下:(一般统一为2个点,其他的是数字,版本号从高位到低位,首位越大则越大,首位相同则对比下一位 ...
- java0425 wen IO
- Jquery实现checkbox按shift多选
html <html> <head> <meta http-equiv="content-type" content="text/html; ...
- linux 安装oracle
报错1:报display相关错误su - oracleDISPLAY=redhat64-2:1 --此处为远程会话地址(可以写localhost或IP均可)export DISPLAYcd /home ...
- 7-27 Codeforces Round #499 (Div. 2)
C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...
- gulp自动化构建工具的使用
gulp自动化构建工具: 把前端开发常见的处理(“搬砖”)程序,通过一个工具模块管理起来,只需配置一次,达到自动处理目的,简化开发,提高效率!! 安装: 1.全局安装(全局安装一个gulp命令) A. ...
- 论文笔记:Heterogeneous Memory Enhanced Multimodal Attention Model for Video Question Answering
Heterogeneous Memory Enhanced Multimodal Attention Model for Video Question Answering 2019-04-25 21: ...
- 如何在Windows上的Jupyter Notebook中安装和运行PySpark
When I write PySpark code, I use Jupyter notebook to test my code before submitting a job on the clu ...