国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

看透springMvc源代碼分析與實(shí)現(xiàn)這本書中第八章實(shí)例總結(jié)(controller和View)

2019-11-08 01:55:27
字體:
供稿:網(wǎng)友

在搭建項(xiàng)目過程中順利完成,(如何搭建詳見《看透sPRingMvc源代碼分析與實(shí)現(xiàn)》這本書中第八章).啟動(dòng)之后遇到的問題如下:

項(xiàng)目可以成功啟動(dòng),但是訪問URL時(shí)后臺(tái)報(bào)錯(cuò)

Configuration problem: Cannot locate BeanDefinitionParser for element [view-resolvers]

出現(xiàn)這個(gè)問題的原因是項(xiàng)目lib里的spring-webmvc-4.2.5.RELEASE.之前用的是spring-webmvc-3.2.0.RELEASE這個(gè)版本,由于版本低問題導(dǎo)致xml中schema找不到[view-resolvers],大家有時(shí)間可以去看看,3.2.0.RELEASE這個(gè)版本的所有xsd均沒有[view-resolvers],4.2.5.RELEASE這個(gè)版本spring-mvc-4.2.xsd和spring-mvc-4.1.xsd這兩個(gè)有

其中的[view-resolvers]在配置文件中配置:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="  http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-4.2.xsd  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-4.2.xsd  http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd ">   <mvc:annotation-driven></mvc:annotation-driven>  <context:component-scan base-package="com.game"></context:component-scan>   <!-- <mvc:view-resolvers>  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="WEB-INF/views/jsp" p:suffix=".jsp"></bean>  </mvc:view-resolvers> --> <mvc:view-resolvers> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp"></bean>  </mvc:view-resolvers>  <!--  <bean id = "helloworld" class="com.game.controller.Helloworld">  </bean>  --></beans>

---------------------------------------------------------------------------------------------------------------

由于 <mvc:view-resolvers>需要較高的jar版本,配置起來需要好多新的jar,所以我配置viewresolver用的另一種:

<!-- 對(duì)轉(zhuǎn)向頁面的路徑解析。prefix:前綴, suffix:后綴 -->    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp" /> 

用這個(gè)替換標(biāo)紅的,同樣可以實(shí)現(xiàn)。

這個(gè)有一個(gè)問題是在controler中,showArticle方法的articleId一直取不到值。不知道是不是配置中沒用<mvc:view-resolvers>   導(dǎo)致的,覺得原書中能取到也挺不可思議的

@RequestMapping(value={"/articles/{articleId}/comment"})public String doComment(@PathVariable String articleId,RedirectAttributes attributes,Model model)throws Exception{String comment=(String) model.asMap().get("comment");comment=new String (comment.getBytes("UTF-8"));attributes.addFlashAttribute("comment", (String) model.asMap().get("comment"));model.addAttribute("articleId", articleId);return "redirect:/showArticle";}

@RequestMapping(value={"/showArticle"},method={RequestMethod.GET})public String showArticle(Model model,sessionStatus sessionStatus) throws Exception{String articleId =(String)model.asMap().get("articleId");model.addAttribute("articleTitle", articleId+"號(hào)文章標(biāo)題");model.addAttribute("article",articleId+"號(hào)文章內(nèi)容");sessionStatus.setComplete();return "article";}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 仙游县| 丰原市| 元阳县| 福海县| 湘乡市| 永平县| 平原县| 新建县| 秭归县| 益阳市| 上栗县| 兴义市| 英德市| 周宁县| 江山市| 鄂尔多斯市| 澄城县| 阳春市| 长宁区| 神池县| 喜德县| 搜索| 桃源县| 从化市| 新津县| 遂昌县| 云林县| 突泉县| 大田县| 闵行区| 平定县| 阿图什市| 泰宁县| 沙湾县| 辉南县| 英超| 方正县| 闽清县| 左权县| 锡林郭勒盟| 忻城县|