当前位置: 首页 > news >正文

SpringBoot复习:(28)【前后端不分离】自定义View

一、自定义View

package cn.edu.tju.view;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;@Component
public class MyView implements View {@Overridepublic String getContentType() {return "text/html";}@Overridepublic void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {response.getWriter().write("hello, world.this is my view");}
}

二、控制器返回视图名称指向上述View

package cn.edu.tju.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class ViewController {@RequestMapping("/view")public String getView(){return "myView";}
}

BeanNameViewResolver就会把我自定义的myView这个视图解析到MyVIew这个view类。

http://www.lryc.cn/news/119883.html

相关文章:

  • springcloud3 springcloud stream的学习以及案例(了解)
  • Kotlin理解内置函数
  • 手机app测试
  • Centos部署Git
  • k8s 控制器
  • 谷歌关闭跨域限制.(生成一个开发浏览器),Chrome关闭跨域
  • 实践指南-前端性能提升 270% | 京东云技术团队
  • 8月11日上课内容 nginx的多实例和动静分离
  • 腾讯云CVM服务器端口在安全组中打开!
  • k8s、docker添加daemon.json添加“exec-opts“: [“native.cgroupdriver=systemd“]后无法启动的问题
  • React组件性能优化实践
  • SpringBoot复习:(29)静态资源的配置路径
  • mysql延时问题排查
  • 接口设置了responseType:‘blob‘后,接收不到后端错误信息
  • 无涯教程-Perl - mkdir函数
  • css3 瀑布流布局遇见截断下一列展示后半截现象
  • C++初阶之一篇文章教会你list(理解和使用)
  • 如何给Linux开启swap虚拟内存
  • spring按条件注入@Condition及springboot对其的扩展
  • MySQL多表连接查询3
  • 【从零开始学习JAVA | 第四十五篇】反射
  • 顺丰科技数据治理实践
  • Nginx+Tomcat负载均衡、动静分离实例详细部署
  • Java多线程(3)---锁策略、CAS和JUC
  • Linux:Shell编辑之文本处理器(awk)
  • 探索FSM (有限状态机)应用
  • 6.continue break
  • 如何在Linux中强制关闭卡住的PyCharm
  • c# Excel数据的导出与导入
  • Kotlin~Mediator中介者模式