设为首页 加入收藏

TOP

SpringBoot | 第十六章:web 应用开发(三)
2018-09-05 11:46:45 】 浏览:404
Tags:SpringBoot 十六 web 应用开发
uot;name", name); map.addAttribute("from", "lqdev.cn"); //模版名称,实际的目录为:src/main/webapp/jsp/index.html return "index"; } @GetMapping("/mv") public ModelAndView index(String name) { ModelAndView mv = new ModelAndView(); mv.addObject("name", name); mv.addObject("from", "lqdev.cn"); //模版名称,实际的目录为:src/main/webapp/jsp/index.html mv.setViewName("index"); return mv; } }

 

3.webapp/WEB-INF/jsp目录下编写jsp文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charsetUTF-8">
<title>jsp示例</title>
</head>
<body>
<h1>Hello Jsp</h1>
<h2 >名称:${name},来自:${from}</h2>
</body>
</html>

5.启动应用,访问:http://127.0.0.1:8080/jsp/mv?name=oKong 或者 http://127.0.0.1:8080/jsp/map?name=oKong 就能查看页面了。


这里需要注意:在使用spring-boot-maven-plugin打包插件时,默认情况下打包的应用时访问不了jsp目录文件的,需要把版本修改为1.4.2.RELEASE版本,同时pom中加入resource配置:

<resources>
	<!-- 打包时将jsp文件拷贝到META-INF目录下 -->
	<resource>
		<!-- 指定resources插件处理哪个目录下的资源文件 -->
		<directory>src/main/webapp</directory>
		<!--注意此次必须要放在此目录下才能被访问到 -->
		<targetPath>META-INF/resources</targetPath>
		<includes>
			<include>**/**</include>
		</includes>
	</resource>
<!-- 	<resource>
	  	指定resources插件处理哪个目录下的资源文件
		<directory>src/main/resources/static</directory>
		注意此次必须要放在此目录下才能被访问到
		<targetPath>META-INF/resources/static</targetPath>
		<includes>
			<include>**/**</include>
		</includes>
	</resource> -->
	<resource>
		<directory>src/main/resources</directory>
		<includes>
			<include>**/**</include>
		</includes>
<!-- 		<excludes>
		   <exclude>src/main/resources/static/**</exclude>
		</excludes> -->
		<filtering>false</filtering>
	</resource>
</resources>

相关资料

  1. https://docs.spring.io/spring-boot/docs/1.5.14.RELEASE/reference/htmlsingle
  2. https://blog.csdn.net/qq_34665539/article/details/74783910

总结

本章节主要是讲解了利用模版引擎进行动态页面实现功能。对于有此需要的同学可以去看下使用的模版引擎的相关使用教程,这里就不多加阐述了,毕竟目前工作现在用这个的机会比较少了,也只是知道个大概使用,具体一些深入的使用还是看具体的官方文档吧!

最后

目前互联网上很多大佬都有SpringBoot系列教程,如有雷同,请多多包涵了。本文是作者在电脑前一字一句敲的,每一步都是实践的。若文中有所错误之处,还望提出,谢谢。

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇按钮条件逻辑配置化的可选技术方案 下一篇oracle 中 print_table 存储过程..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目