SpringMVC-08-SpringMVC层编写
SpringMVC层编写
web.xml
DispatcherServlet<!--DispatcherServlet-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
乱码问题<!--乱码过滤-->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Session<!--Session-->
<session-config>
<session-timeout>15</session-timeout>
</session-config>
spring-mvc.xml
注解驱动<!--1. 注解驱动-->
<mvc:annotation-driven/>
静态资源过滤<!--2. 静态资源过滤-->
<mvc:default-servlet-handler/>
扫描包<!--3. 扫描包:controller-->
<context:component-scan base-package="com.kuang.controller"/>
视图解析器<!--4. 视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Spring配置整合文件
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:spring-dao.xml"/>
<import resource="classpath:spring-service.xml"/>
<import resource="classpath:spring-mvc.xml"/>
</beans>
排错思路
问题1:bean不存在
步骤:
查看这个bean注入是否成功
junit单元测试,观察代码是否可以查询出结果
前两步都没问题的话,问题不在我们的底层,是spring出了问题
springMVC整合的时候没有调用到service层的bean:
applicationContext.xml没有注入bean
web.xml中,我们也绑定过配置文件!发现问题,我们配置的是spring-mvc.xml,这里确实没有service bean,所以报空指针。
问题2:http://localhost:8080/book/allBook 404
原因:applicationContext.xml没有import spring-mvc.xml
SpringMVC-08-SpringMVC层编写的更多相关文章
- SpringMVC学习--springmvc和mybatis整合
简介 springMVC是表现层,service充当业务层,mybatis作为持久层,通过spring将这三层整合起来.如下图: 第一步:整合dao层 mybatis和spring整合,通过sprin ...
- 【SpringMVC】SpringMVC 入门
SpringMVC 入门 文章源码 SpringMVC 基本概念 在 JavaEE 开发中,几乎全都是基于 B/S 架构的开发.在 B/S 架构中,系统标准的三层架构包括:表现层.业务层.持久层. 表 ...
- SpringMVC(一) SpringMVC概述
SpringMVC为展现层提供的基于MVC设计理念的优秀的WEB框架,是目前主流的MVC框架之一.Spring 3.0之后,超越Struts2成为最优秀的MVC框架. SpringMVC通过一套MVC ...
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_01.SpringMVC概述及入门案例
第二章 第三章 第四章 三层框架 springMvc是表现层
- SpringMVC(一) 简单代码编写,注解,重定向与转发
SpringMVC是什么 SpringMVC是目前最好的实现MVC设计模式的框架,是Spring框架的一个分支产品,以SpringIOC容器为基础,并利用容器的特性来简化它的配置.SpringMVC相 ...
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_05.入门程序之入门代码编写
先把默认的index.jsp删掉.默认的index.jsp没有jsp的声明 ok webapp文件夹下new一个 起名叫做index.新建的页面有jsp的头 创建控制器类 java下新建一个class ...
- 08.SpringMVC之方法返回值
返回ModelAndView Controller类方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view.之前我就已讲过,在此并不过多赘述. 返回void 在Cont ...
- SpringMVC在Controller层中注入request的坑
记一次为了节省代码没有在方法体中声明HttpServletRequest,而用autowire直接注入所钻的坑 结论 给心急的人. 直接在Controller的成员变量上使用@Autowire声明Ht ...
- SpringMVC的controller层接收来自jsp页面通过<a href="/user/userUpdateInfo/>的中文乱码问题
这种情况是,jsp页面的中文正常显示,数据的中文也是正常显示,但是在Controller层接收到的中文是乱码,如下图所示: 解决方法:在Controller层对前台传递的中文乱码进行处理,将它转换成u ...
随机推荐
- JavaScript 把数组扁平化的方法
使用 ES2019中的新特性 Array.prototype.flat() const arr = [1,2,3,4,[10,20,30]] const res = arr.flat() consol ...
- python3 - selenium常用的参数
# 选用开发者模式,创建一个浏览器对象,可避免被检测到是selenium模拟浏览器 chrome_options = webdriver.ChromeOptions() chrome_options ...
- Python默认参数的陷阱
一:内置函数 globals() locals() 1.返回的是字典,字典里面的键值对:全局作用域的全部内容 print(globals()) 2.返回的是字典,字典里面的键值对:当前作用域的全部内容 ...
- (转)@Autowired(required=false)注入注意的问题
1.前言 在使用spring开发过程中,我们基本上都是使用@Autowired这个注解,用来注入已有的bean.但是有些时候,会注入失败.当我们加上参数(required=false)就能解决.今天整 ...
- Javascript模块化编程(二):AMD规范 (转)
原文作者: 阮一峰 日期: 2012年10月30日 这个系列的第一部分介绍了Javascript模块的基本写法,今天介绍如何规范地使用模块. (接上文) 七.模块的规范 先想一想,为什么模块很重要? ...
- Mybatis_day2
二 mybatis配置详解 MyBatis最关键的组成部分是SqlSessionFactory,我们可以从中获取SqlSession, 并执行映射的SQL语句.SqlSessionFactory对象可 ...
- ucore lab2
CPU在如下时刻会检查特权级 访问数据段 访问页 进入中断服务例程(ISR) RPL位于段寄存器 DS ES FS GS CPL位于CS SS DPL位于段描述符表/门描述符 访问门时: CPL< ...
- Galera Cluster for MySQL 集群恢复
node1: 1.rm -rf grastate.dat 2.mysqld_safe --wsrep-recover 3.galera_new_cluster node2: systemctl res ...
- 前端Web APIs 二
day04 - Web APIs 学习目标: 能够说出常用的3-5个键盘事件 能够知道如何获取当前键盘按下的是哪个键 能够知道浏览器的顶级对象window 能够使用window.onload事件 能够 ...
- SEO大神都是些什么人
http://www.wocaoseo.com/thread-97-1-1.html 貌似好久没有更新seo培训联盟的文章了,最近一直在专心学习其他的东西,前一段写了几篇关于用户需求和体验的文章,但是 ...