日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > spring boot 學(xué)習(xí)--08---搭建ssmm-02

spring boot 學(xué)習(xí)--08---搭建ssmm-02

來源:程序員人生   發(fā)布時(shí)間:2016-09-28 10:13:05 閱讀次數(shù):2586次

接上篇http://blog.csdn.net/javastudyr/article/details/52585770
這篇開始來配置springmvc,并測試

思路:
- 在web.xml配置servlet
- 創(chuàng)建springmvc配置文件
- 創(chuàng)建TestController
- 創(chuàng)建測試頁面
- 基本測試
- 亂碼測試
- 時(shí)間測試

(1)web.xml配置springmvc

<!-- springmvc servlet配置 --> <servlet> <servlet-name>front</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>front</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>

(2)創(chuàng)建spring-mvc.xml 文件
springmvc 配置掃描,自動(dòng)裝配,JSP解析

<context:component-scan base-package="com.study" use-default-filters="false"> <!--掃描 cn.itcast下的 所有類中 注解是 Controller的類 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!--自動(dòng)裝配 --> <context:annotation-config/> <!-- Jsp的視圖解析器 --> <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/"/> <property name="suffix" value=".jsp"/> </bean>

(3)創(chuàng)建TestController

package com.study.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.study.bean.TestTb; Controller public class TestController { @RequestMapping("/test/springmvc/testTbAdd") public String test_testtb(TestTb tb){ System.out.println(tb.toString()); return "success"; } }

(4)創(chuàng)建測試頁面和success頁面,src/main/webapp/下創(chuàng)建index.jsp ,注意修改編碼

<%@ page language="java" contentType="text/html; charset=UTF⑻" pageEncoding="UTF⑻"%> <!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; charset=UTF⑻"> <title>Insert title here</title> </head> <body> <form action="test/springmvc/testTbAdd.do" method="POST"> 名稱:<input type="text" name="name"/><br/> <input type="submit" value="提交"/> </form> </body> </html>

在webapp/WEB-INF/view/下創(chuàng)建success.jsp

<%@ page language="java" contentType="text/html; charset=UTF⑻" pageEncoding="UTF⑻"%> <!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; charset=UTF⑻"> <title>Insert title here</title> </head> <body> 添加成功! </body> </html>

(5)開始基本測試
訪問http://localhost:8080/boot-study-ssmm-xml/

這里寫圖片描述

基本測試結(jié)果:
這里寫圖片描述

(6)在TestController中添加方法,開始中文測試

@RequestMapping(value="/test/unicode",produces = "plain/html; charset=UTF⑻") public @ResponseBody String test_unicode(){ return "成功"; }

訪問:
http://localhost:8080/boot-study-ssmm-xml/test/unicode.do

中文測試返回結(jié)果:
這里寫圖片描述

解決辦法
1. 在web.xml 中添加字符攔截器,注意加載到所有servlet,filter的前面

<filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF⑻</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>

中文測試?yán)^續(xù)測試
這里寫圖片描述

這是為何喃,我們加載了字符攔截器,好像還是不行,但是在訪問http://localhost:8080/boot-study-ssmm-xml/ 這個(gè)接口的時(shí)候輸入中文,后臺(tái)是可以接收了
這里寫圖片描述

繼續(xù)解決我們直接返回中文字符串的問題,這里是由于@ResponseBody 注解,這個(gè)注解返回的String,springmvc會(huì)直接用org.springframework.http.converter.StringHttpMessageConverter 來進(jìn)行轉(zhuǎn)發(fā),這個(gè)沉默的編碼是:ISO⑻859⑴
這里寫圖片描述

明白了,現(xiàn)在我們可以在springmvc中配置這個(gè)StringHttpMessageConverter 的編碼

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <list> <bean class = "org.springframework.http.converter.StringHttpMessageConverter"> <property name = "supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean>

中文測試?yán)^續(xù)測試2

結(jié)果:
這里寫圖片描述

(7)時(shí)間測試

index.jsp修改以下

<%@ page language="java" contentType="text/html; charset=UTF⑻" pageEncoding="UTF⑻"%> <!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; charset=UTF⑻"> <title>Insert title here</title> </head> <body> <form action="test/springmvc/testTbAdd.do" method="POST"> 名稱:<input type="text" name="name"/><br/> 生日:<input type="text" name="birthday"/> <input type="submit" value="提交"/> </form> </body> </html>

時(shí)間測試:
這里寫圖片描述

400,毛病,估計(jì)就是時(shí)間類型不匹配,我們在TestController中綁定1個(gè)時(shí)間解析來試試

/** * 注冊日期格式 * @param request * @param binder */ @InitBinder public void InitBinder(HttpServletRequest request ,ServletRequestDataBinder binder){ DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); binder.registerCustomEditor(Date.class, new CustomDateEditor(df, false)); }

時(shí)間測試1
這里寫圖片描述

OK,到此所有的都大功告成

補(bǔ)充1下:時(shí)間轉(zhuǎn)換器也能夠全區(qū)配置,在springmvc中,配置以下:

<!-- 全局時(shí)間配置 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <!-- 自定義事件處理器 --> <bean class= "com.study.util.BindindInitializer" /> </property> </bean>
package com.study.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.context.request.WebRequest; public class BindindInitializer implements WebBindingInitializer{ public void initBinder(WebDataBinder binder, WebRequest request) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); binder.registerCustomEditor(Date.class, new CustomDateEditor(df, false)); } }

下篇就正式進(jìn)入springboot的開發(fā)了

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产热re99久久6国产精品 | 狠狠色综合欧美激情 | 岛国av免费观看 | 无码精品一区二区三区免费视频 | 青青青国产视频 | 亚洲欧美激情视频 | 成人国产在线视频 | 成人ssswww在线播放 | 久久久久国产一区二区三区四区 | 91短视频在线视频 | 在线地址一地址二免费看 | 国产精品18久久久久久久网站 | 国产在线精品一区二区 | 精品久久久影院 | 中文字幕免费 | 久久久亚洲欧洲 | 毛片com | 成年人免费视频观看 | 久久精品1| 国产激情二区 | 免费观看日韩毛片 | 国产精品66 | www.成人| 欧美在线色 | 国产精品三级一区二区 | 福利视频三区 | 欧美中文 | 婷婷久久久 | 精品国产成人 | 欧美怡红院视频 | 一区二区三区中文字幕 | 在线影视 | 一级片网址 | 美女又黄又爽 | 91久久精品一区二区二区 | 亚洲区久久 | 国产精品美女一区二区 | 国产精品69久久久久水密桃 | 国产精品久久久久久久久久免费 | 久久精品一区二区 | 久久久国产精品入口麻豆 |