Spring boot的Controller类是如何指定HTML页面的

2020-06-25 综合 164阅读
Spring boot的Controller类是指定HTML页面的实现的方法如下:
1、在spring boot中借鉴servlet的方法输出html:
@RequestMapping(value="/getPage")
public void writeSubmitHtml(Reader reader, Writer writer, HttpSession session) throws IOException {
User user = (User) session.getAttribute(ConstantConfig.LONGIN_USER);
StringBuffer sbHtml = new StringBuffer();
sbHtml.append("");
sbHtml.append("支付宝即时到账交易接口</title></head><body>"+ user.getNo() +"</body></html>");<br /> writer.write(sbHtml.toString()); <br /> }<br />这里直接使用了参数 Writer writer,返回值为 void, 其实参数 Writer writer 也可以换成 PrintWriter writer; 直接写出HTML的字符流。<br />2.在controller中的配置:<br />@RequestMapping(value="/htmlView")<br /> public void htmlView(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{<br /> // ...<br /> request.getRequestDispatcher("index.html").forward(request, response);<br /> //response.sendRedirect("<a href="http://www.baidu.com" target="_blank" rel="nofollow noopener">http://www.baidu.com</a>");<br /> } </div> <div class="tags"> </div> <div class="clear"> <div class="shares"> <b>声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com</b> <div id="share" class="share-component social-share" data-sites="weibo,qzone,qq,wechat"> </div> </div> <div class="act"> <a href="JavaScript:" onclick="zan('1670868096555737107')" class="zan" title="赞"> <i class="iconfont bx bx-like"></i> <span id="zan">0</span> </a> </div> </div> <div class="clear"></div> </div> <div class="ny-ad"> </div> <div class="ny-ad"> </div> <div class="like"> <h3 class="title">最新文章</h3> <div class="piclist likep"> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/751110905729851452.html" title="和顺府在生了七个嫡子终于生了一个嫡女对此老侯爷给全家人说给我宠是女主叫王拟宝什么小说"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/11" class="cat">综合 </a> <h3> <a href="https://w.sf024.com/info/751110905729851452.html" title="和顺府在生了七个嫡子终于生了一个嫡女对此老侯爷给全家人说给我宠是女主叫王拟宝什么小说">和顺府在生了七个嫡子终于生了一个嫡女对此老侯爷给全家人说给我宠是女主叫王拟宝什么小说</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 170阅读 </span> </div> </div> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/652223498541083205.html" title="求问cad作图之类的cpu用e3好还是i5"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/11" class="cat">综合 </a> <h3> <a href="https://w.sf024.com/info/652223498541083205.html" title="求问cad作图之类的cpu用e3好还是i5">求问cad作图之类的cpu用e3好还是i5</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 134阅读 </span> </div> </div> <div class="li"> <div class="img"> <a href="https://w.sf024.com/info/203839841240316485.html" title="csgo用5e对战平台玩可以降低延迟吗?我的网络用官方服务器太卡了"> <img src="https://w.sf024.com/assets/img/default.jpg" alt=""> </a> </div> <a href="https://w.sf024.com/ask/11" class="cat">综合 </a> <h3> <a href="https://w.sf024.com/info/203839841240316485.html" title="csgo用5e对战平台玩可以降低延迟吗?我的网络用官方服务器太卡了">csgo用5e对战平台玩可以降低延迟吗?我的网络用官方服务器太卡了</a> </h3> <div class="meta"> <span class="time"> <i class="iconfont bx bx-time"></i> 04-15 </span> <span class="views"> <i class="iconfont bx bx-show"></i> 823阅读 </span> </div> </div> <div class="clear"></div> </div> </div> <div class="ny-ad"> </div> </div> <div class="sidebar"> <div class="widget postlist"> <h3>猜你喜欢</h3> <ul class="hasimg"> <li> <a href="https://w.sf024.com/info/1670868096555737107.html" title="Spring boot的Controller类是如何指定HTML页面的" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="Spring boot的Controller类是如何指定HTML页面的"> </a> <a href="https://w.sf024.com/info/1670868096555737107.html" target="">Spring boot的Cont...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 06-25 </span><span> <i class="iconfont bx bx-show"></i> 164阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1831831765595678380.html" title="请教spring mvc 3如何通过URL快速定位使用注解的controller类" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="请教spring mvc 3如何通过URL快速定位使用注解的controller类"> </a> <a href="https://w.sf024.com/info/1831831765595678380.html" target="">请教spring mvc 3如何...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-03 </span><span> <i class="iconfont bx bx-show"></i> 80阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1308089583886326099.html" title="如何设置Spring Boot中@RequestBody反序列化实体的默认值" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="如何设置Spring Boot中@RequestBody反序列化实体的默认值"> </a> <a href="https://w.sf024.com/info/1308089583886326099.html" target="">如何设置Spring Boot中...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 09-02 </span><span> <i class="iconfont bx bx-show"></i> 433阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1545730408932364947.html" title="Spring中@Controller和@RestController之间的区别" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="Spring中@Controller和@RestController之间的区别"> </a> <a href="https://w.sf024.com/info/1545730408932364947.html" target="">Spring中@Controll...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-08 </span><span> <i class="iconfont bx bx-show"></i> 71阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1544441091093659547.html" title="controller是spring的注解还是springmvc的注解" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="controller是spring的注解还是springmvc的注解"> </a> <a href="https://w.sf024.com/info/1544441091093659547.html" target="">controller是sprin...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-05 </span><span> <i class="iconfont bx bx-show"></i> 79阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/26838666202.html" title="spring mvc中的controller常用的注解有哪些" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="spring mvc中的controller常用的注解有哪些"> </a> <a href="https://w.sf024.com/info/26838666202.html" target="">spring mvc中的cont...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 11-20 </span><span> <i class="iconfont bx bx-show"></i> 114阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/395453737329957205.html" title="spring的controller默认是单例还是多例" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="spring的controller默认是单例还是多例"> </a> <a href="https://w.sf024.com/info/395453737329957205.html" target="">spring的controlle...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 08-19 </span><span> <i class="iconfont bx bx-show"></i> 22阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/1546003538638676467.html" title="spring boot 怎么启动" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="spring boot 怎么启动"> </a> <a href="https://w.sf024.com/info/1546003538638676467.html" target="">spring boot 怎么启动...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 05-04 </span><span> <i class="iconfont bx bx-show"></i> 96阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/750199924443329052.html" title="spring boot 官方文档怎么学习" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="spring boot 官方文档怎么学习"> </a> <a href="https://w.sf024.com/info/750199924443329052.html" target="">spring boot 官方文档...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 05-04 </span><span> <i class="iconfont bx bx-show"></i> 84阅读 </span> </p> </li> <li> <a href="https://w.sf024.com/info/876896028603932692.html" title="spring boot liunx 怎么启动" class="img"> <img src="https://w.sf024.com/assets/img/default.jpg" alt="spring boot liunx 怎么启动"> </a> <a href="https://w.sf024.com/info/876896028603932692.html" target="">spring boot liun...</a> <p class="meta"> <span> <i class="iconfont bx bx-time"></i> 05-11 </span><span> <i class="iconfont bx bx-show"></i> 12阅读 </span> </p> </li> </ul> </div> </div> </div> </section> <footer class="footer"> <div class="container"> <p class="copyright">COPYRIGHT 2013 - 2024 你问我答网®. ALL RIGHTS RESERVED. | <a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2020035127号</a></p> </div> </footer> <script> let search_type="1"; var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?752ceaa2e03e39366ceff9a414a1f6a7"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();</script> <script type="text/javascript" src="https://w.sf024.com/assets/js/jquery.share.min.js"></script> </body> </html>