Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
在使用SpringBoot開發(fā)web應用時實際采用的是spring mvc來實現,現在采用REST風格的開發(fā)方式越來越多spring當然也支持這一開發(fā)模式。
代碼環(huán)境spring boot 頁面配置為使用jsp的方式
rest模式我就不介紹了,主要是GET、POST、PUT、DELETE方法,spring mvc也提供了對應的實現方式
@RequestMapping(method=RequestMethod.GET)
@RequestMapping(method=RequestMethod.POST)
@RequestMapping(method=RequestMethod.PUT)
@RequestMapping(method=RequestMethod.DELETE)
當然也可以使用
@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
這與上面的是一樣的效果
下面我們來一個一個的實現
GetMapping
@GetMapping("/httpMethod") public String httpMethd(){ return "test/test"; }
使用這個代碼我們定義了一個get方法,通過這個方法spring boot會自動跳轉到test目錄下的test.jsp頁面當然你還可以在@GetMapping下面再加上@ResponseBody,這樣返回的就是一個字符串而不是跳轉頁面了。
PostMapping
test.jsp頁面
<%-- Created by IntelliJ IDEA. User: jacky Date: 17-10-3 Time: 下午4:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>HttpMethodTest</title> </head> <body> <form action="/httpMethod" method="post"> 名稱 <input type="text" name="name"> <br> 密碼 <input type="text" name="pwd"> <br> <input type="submit" name="提交"> </form> </body> </html>
controller類
@PostMapping("/httpMethod") @ResponseBody public String httpMethod(@RequestParam String name,@RequestParam String pwd){ System.out.println("sent name is "+name); System.out.println("sent pwd is "+pwd); return "success"; }
這里表單定義了提交方法為post,這時提交表單在后臺頁面就能打印處理提交的信息,同時會向前臺返回success字符串。
PutMapping DeleteMapping
本質上瀏覽器端的form表單只支持GET和POST方法并不支持PUT和DELETE方法,但是spring已經解決了這個問題,從spring3.0開始定義了一個filter來支持對PUT和DELETE方法的解析,下面我們就來看看怎么處理。
首先我們要對jsp頁面的表單做一個簡單的修改
<%-- Created by IntelliJ IDEA. User: jacky Date: 17-10-3 Time: 下午4:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>HttpMethodTest</title> </head> <body> <form action="/upload/httpMethod" method="post"> <input type="hidden" name="_method" value="PUT/DELETE"> 名稱 <input type="text" name="name"> <br> 密碼 <input type="text" name="pwd"> <br> <input type="submit" name="提交"> </form> </body> </html>
對比一下就看到了吧,我們添加了一個隱藏的輸入框名字叫_method,值為PUT或者是DELETE
controller代碼
@PutMapping("/httpMethod") @ResponseBody public String httpMethodPut(@RequestParam String name,@RequestParam String pwd){ System.out.println("put sent name is "+name); System.out.println("put sent pwd is "+pwd); return "success"; } @DeleteMapping("/httpMethod") @ResponseBody public String httpMethodDel(@RequestParam String name,@RequestParam String pwd){ System.out.println("delete sent name is "+name); System.out.println("delete sent pwd is "+pwd); return "success"; }
下面是重點了,引入filter,直接看代碼
@Configuration @ImportResource({"classpath:applicationContext.xml"}) public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(MaterialApplication.class); } @Bean public FilterRegistrationBean httpMethodFilterRegistrationBean() { FilterRegistrationBean registrationBean=new FilterRegistrationBean(); registrationBean.setFilter(httpMethodFilter()); registrationBean.addUrlPatterns("/*"); registrationBean.setName("HttpMethodFilter"); registrationBean.setOrder(1); return registrationBean; } @Bean public Filter httpMethodFilter(){ return new HiddenHttpMethodFilter(); }
核心的filter就是HiddenHttpMethodFilter,這是spring自己定義來處理put和delete請求的filter,只需要配置這個filter過濾所有請求就行了,當然你還可以考慮過濾指定的路徑請求。
配置好后就可以測試一下結果。
跳轉到郵箱:
<a href="mailto:someone@microsoft.com?subject=Hello%20again">發(fā)送郵件</a>
<a href="mailto:someone@microsoft.com?cc=someoneelse@microsoft.com&bcc=andsomeoneelse2@microsoft.com&subject=Summer%20Party&body=You%20are%20invited%20to%20a%20big%20summer%20party!">發(fā)送郵件!</a>
圖像映射:
創(chuàng)建圖像映射需要img、map、area三個標簽同時存在,img 元素中的 "usemap" 屬性引用 map 元素中的 "id" 或 "name" 屬性,area中coords屬性為設置或返回圖像映射中可點擊區(qū)域的坐標,area標簽可以設置多個。相關文檔推薦:https://www.w3school.com.cn/html/html_images.asp
<body>
<img src="img.PNG" usemap="#buhuo" alt="捕獲" />
<map name="buhuo" id="buhuo">
<area shape="circle" coords="10,10,100,100" href="上次閱讀位置.PNG" target="_self"alt="沒有圖片!" />
<area shape="circle" coords="10,10,100,100" href="上次閱讀位置.PNG" target="_self"alt="沒有圖片!" />
</map>
</body>
特殊字符:標簽會被解析,采用特殊字符代碼可以代替特殊字符
錨點定位:
通過錨點鏈接,用戶可以快速的定位到目標。
<a href="#two">定位到標題2</a><!-- 使用<a href="#id名">鏈接文本</a>,注意#的使用 -->
<h3>標題1</h3>
<h3 id="two">標題2</h3><!-- 使用id名進行標注供錨點鏈接使用 -->
<h3>標題3</h3>
<h3>標題4</h3>
路徑:
相對路徑:
分為三種情況:1、同級目錄 2、上一級目錄 3、下級目錄
<img src="picture.jpg"/> <!-- 同級目錄下的文件直接寫文件名引入即可 -->
<img src="images/picture.jpg"/> <!-- 下級目錄中的文件需要先進入下一級目錄,然后/找到文件后寫文件名即可 -->
<img src="../images/picture.jpg"/> <!-- 上級目錄中的文件需要先../進入上級目錄,再使用同級目錄的方法查找文件 -->
絕對路徑:
絕對路徑是相對于計算機或者網站(網址)而言的,一般很少使用絕對路徑
<img src="C:\Users\17121\Desktop\picture.jpg"/> <!-- 電腦上面絕對路徑幾乎沒人使用,因為換電腦后,文件就無法使用 -->
<img src="http://webimages/picture.jpg"/> <!-- 網上的絕對路徑經常會被使用,但是文件一旦消失或者主機和域名過期,將無法使用 -->
提示:本文圖片等素材來源于網絡,若有侵權,請發(fā)郵件至郵箱:810665436@qq.com聯系筆者刪除。
筆者:苦海123
其它問題可通過以下方式聯系本人咨詢:
QQ:810665436
微信:ConstancyMan
例
帶有可點擊區(qū)域的圖像映射:
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
瀏覽器支持
目前大多數瀏覽器支持 <map>標簽。
標簽定義及使用說明
<map> 標簽用于客戶端圖像映射。圖像映射指帶有可點擊區(qū)域的一幅圖像。
<img>中的 usemap 屬性可引用 <map> 中的 id 或 name 屬性(取決于瀏覽器),所以我們應同時向 <map> 添加 id 和 name 屬性。
area 元素永遠嵌套在 map 元素內部。area 元素可定義圖像映射中的區(qū)域。
HTML 4.01 與 HTML5之間的差異
注意: 在 HTML5 中, 如果 id 屬性在<map> 標簽中指定, 則你必須同樣指定 name 屬性。
HTML 與 XHTML 之間的差異
在 XHTML 中,name 屬性已經廢棄,使用 id 屬性替換它。
屬性
屬性 | 值 | 描述 |
---|---|---|
name | mapname | 必需。為 image-map 規(guī)定的名稱。 |
全局屬性
<map> 標簽支持全局屬性,查看完整屬性表 HTML全局屬性。
事件屬性
<map> 標簽支持所有 HTML事件屬性。
如您還有不明白的可以在下面與我留言或是與我探討QQ群308855039,我們一起飛!
*請認真填寫需求信息,我們會在24小時內與您取得聯系。