十分钟带你学会SpringMVC,就是这么简单

使用SpringMVC完成简单的认证接口 简单处理为识别调用方的IP,通过IP标识是否认证成功 阅读详情

Springmvc是什么

Spring web mvc和Struts2都属于表现层的框架,它是Spring框架的一部分,我们可以从Spring的整体结构中看得出来,如下图:

十分钟带你学会SpringMVC,就是这么简单

Springmvc处理流程

如下图所示:

十分钟带你学会SpringMVC,就是这么简单

入门程序

需求:使用浏览器显示商品列表

创建web工程

springMVC是表现层框架,需要搭建web工程开发。

如下图创建动态web工程:

十分钟带你学会SpringMVC,就是这么简单

输入工程名,选择配置Tomcat(如果已有,则直接使用),如下图:

十分钟带你学会SpringMVC,就是这么简单

配置Tomcat,如下图:

十分钟带你学会SpringMVC,就是这么简单

选择准备好的Tomcat,这里用的是Tomcat7,如下图:

十分钟带你学会SpringMVC,就是这么简单

选择成功,点击Finish,如下图:

十分钟带你学会SpringMVC,就是这么简单

选择刚刚设置成功的Tomcat,如下图:

十分钟带你学会SpringMVC,就是这么简单

如下图选择web的版本是2.5,可以自动生成web.xml配置文件,

十分钟带你学会SpringMVC,就是这么简单

创建效果如下图:

十分钟带你学会SpringMVC,就是这么简单

导入jar包

从课前资料中导入springMVC的jar包,位置如下图:

十分钟带你学会SpringMVC,就是这么简单

复制jar到lib目录,工程直接加载jar包,如下图:

十分钟带你学会SpringMVC,就是这么简单

加入配置文件

创建config资源文件夹,存放配置文件,如下图:

十分钟带你学会SpringMVC,就是这么简单

创建springmvc.xml

创建SpringMVC的核心配置文件

SpringMVC本身就是Spring的子项目,对Spring兼容性很好,不需要做很多配置。

这里只配置一个Controller扫描就可以了,让Spring对页面控制层Controller进行管理。

创建springmvc.xml

<?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:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<!-- 配置controller扫描包 -->

<context:component-scan base-package="cn.itcast.springmvc.controller" />

</beans>

配置文件需要的约束文件,位置如下图:

十分钟带你学会SpringMVC,就是这么简单

创建包cn.itcast.springmvc.controller

效果如下图:

十分钟带你学会SpringMVC,就是这么简单

配置前端控制器

配置SpringMVC的前端控制器DispatcherServlet

在web.xml中

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

id="WebApp_ID" version="2.5">

<display-name>springmvc-first</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

<!-- 配置SpringMVC前端控制器 -->

<servlet>

<servlet-name>springmvc-first</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<!-- 指定SpringMVC配置文件 -->

<!-- SpringMVC的配置文件的默认路径是/WEB-INF/${servlet-name}-servlet.xml -->

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:springmvc.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>springmvc-first</servlet-name>

<!-- 设置所有以action结尾的请求进入SpringMVC -->

<url-pattern>*.action</url-pattern>

</servlet-mapping>

</web-app>

加入jsp页面

把参考资料中的itemList.jsp复制到工程的/WEB-INF/jsp目录下,如下图:

十分钟带你学会SpringMVC,就是这么简单

十分钟带你学会SpringMVC,就是这么简单

实现显示商品列表页

创建pojo

分析页面,查看页面需要的数据,如下图:

十分钟带你学会SpringMVC,就是这么简单

创建商品pojo

public class Item {

// 商品id

private int id;

// 商品名称

private String name;

// 商品价格

private double price;

// 商品创建时间

private Date createtime;

// 商品描述

private String detail;

创建带参数的构造器

set/get。。。

}

创建ItemController

ItemController是一个普通的java类,不需要实现任何接口。

需要在类上添加@Controller注解,把Controller交由Spring管理

在方法上面添加@RequestMapping注解,里面指定请求的url。其中".action"可以加也可以不加。

@Controller

public class ItemController {

// @RequestMapping:里面放的是请求的url,和用户请求的url进行匹配

// action可以写也可以不写

@RequestMapping("/itemList.action")

public ModelAndView queryItemList() {

// 创建页面需要显示的商品数据

List<Item> list = new ArrayList<>();

list.add(new Item(1, "1华为 荣耀8", 2399, new Date(), "质量好!1"));

list.add(new Item(2, "2华为 荣耀8", 2399, new Date(), "质量好!2"));

list.add(new Item(3, "3华为 荣耀8", 2399, new Date(), "质量好!3"));

list.add(new Item(4, "4华为 荣耀8", 2399, new Date(), "质量好!4"));

list.add(new Item(5, "5华为 荣耀8", 2399, new Date(), "质量好!5"));

list.add(new Item(6, "6华为 荣耀8", 2399, new Date(), "质量好!6"));

// 创建ModelAndView,用来存放数据和视图

ModelAndView modelAndView = new ModelAndView();

// 设置数据到模型中

modelAndView.addObject("list", list);

// 设置视图jsp,需要设置视图的物理地址

modelAndView.setViewName("/WEB-INF/jsp/itemList.jsp");

return modelAndView;

}

}

启动项目测试

启动项目,浏览器访问地址

效果如下图:

十分钟带你学会SpringMVC,就是这么简单

为什么可以用呢?我们需要分析一下springMVC的架构图。

Springmvc架构

框架结构

框架结构如下图:

十分钟带你学会SpringMVC,就是这么简单

架构流程

1、 用户发送请求至前端控制器DispatcherServlet

2、 DispatcherServlet收到请求调用HandlerMapping处理器映射器。

3、 处理器映射器根据请求url找到具体的处理器,生成处理器对象及处理器拦截器(如果有则生成)一并返回给DispatcherServlet。

4、 DispatcherServlet通过HandlerAdapter处理器适配器调用处理器

5、 执行处理器(Controller,也叫后端控制器)。

6、 Controller执行完成返回ModelAndView

7、 HandlerAdapter将controller执行结果ModelAndView返回给DispatcherServlet

8、 DispatcherServlet将ModelAndView传给ViewReslover视图解析器

9、 ViewReslover解析后返回具体View

10、 DispatcherServlet对View进行渲染视图(即将模型数据填充至视图中)。

11、 DispatcherServlet响应用户

组件说明

以下组件通常使用框架提供实现:

&middot; DispatcherServlet:前端控制器

用户请求到达前端控制器,它就相当于mvc模式中的c,dispatcherServlet是整个流程控制的中心,由它调用其它组件处理用户的请求,dispatcherServlet的存在降低了组件之间的耦合性。

&middot; HandlerMapping:处理器映射器

HandlerMapping负责根据用户请求url找到Handler即处理器,springmvc提供了不同的映射器实现不同的映射方式,例如:配置文件方式,实现接口方式,注解方式等。

&middot; Handler:处理器

Handler 是继DispatcherServlet前端控制器的后端控制器,在DispatcherServlet的控制下Handler对具体的用户请求进行处理。

由于Handler涉及到具体的用户业务请求,所以一般情况需要程序员根据业务需求开发Handler。

&middot; HandlAdapter:处理器适配器

通过HandlerAdapter对处理器进行执行,这是适配器模式的应用,通过扩展适配器可以对更多类型的处理器进行执行。

下图是许多不同的适配器,最终都可以使用usb接口连接

十分钟带你学会SpringMVC,就是这么简单十分钟带你学会SpringMVC,就是这么简单十分钟带你学会SpringMVC,就是这么简单

&middot; ViewResolver:视图解析器

View Resolver负责将处理结果生成View视图,View Resolver首先根据逻辑视图名解析成物理视图名即具体的页面地址,再生成View视图对象,最后对View进行渲染将处理结果通过页面展示给用户。

&middot; View:视图

springmvc框架提供了很多的View视图类型的支持,包括:jstlView、freemarkerView、pdfView等。我们最常用的视图就是jsp。

一般情况下需要通过页面标签或页面模版技术将模型数据通过页面展示给用户,需要由程序员根据业务需求开发具体的页面。

默认加载的组件

我们没有做任何配置,就可以使用这些组件

因为框架已经默认加载这些组件了,配置文件位置如下图:

十分钟带你学会SpringMVC,就是这么简单

# Default implementation classes for DispatcherServlet's strategy interfaces.

# Used as fallback when no matching beans are found in the DispatcherServlet context.

# Not meant to be customized by application developers.

org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver

org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver

org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,

org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping

org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,

org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter

org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver,

org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,

org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver

org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator

org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver

org.springframework.web.servlet.FlashMapManager=org.springframework.web.servlet.support.SessionFlashMapManager

组件扫描器

使用组件扫描器省去在spring容器配置每个Controller类的繁琐。

使用<context:component-scan>自动扫描标记@Controller的控制器类,

在springmvc.xml配置文件中配置如下:

<!-- 配置controller扫描包,多个包之间用,分隔 -->

<context:component-scan base-package="cn.itcast.springmvc.controller" />

注解映射器和适配器

配置处理器映射器

注解式处理器映射器,对类中标记了@ResquestMapping的方法进行映射。根据@ResquestMapping定义的url匹配@ResquestMapping标记的方法,匹配成功返回HandlerMethod对象给前端控制器。

HandlerMethod对象中封装url对应的方法Method。

从spring3.1版本开始,废除了DefaultAnnotationHandlerMapping的使用,推荐使用RequestMappingHandlerMapping完成注解式处理器映射。

在springmvc.xml配置文件中配置如下:

<!-- 配置处理器映射器 -->

<bean

class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />

注解描述:

@RequestMapping:定义请求url到处理器功能方法的映射

配置处理器适配器

注解式处理器适配器,对标记@ResquestMapping的方法进行适配。

从spring3.1版本开始,废除了AnnotationMethodHandlerAdapter的使用,推荐使用RequestMappingHandlerAdapter完成注解式处理器适配。

在springmvc.xml配置文件中配置如下:

<!-- 配置处理器适配器 -->

<bean

class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />

注解驱动

直接配置处理器映射器和处理器适配器比较麻烦,可以使用注解驱动来加载。

SpringMVC使用<mvc:annotation-driven>自动加载RequestMappingHandlerMapping和RequestMappingHandlerAdapter

可以在springmvc.xml配置文件中使用<mvc:annotation-driven>替代注解处理器和适配器的配置。

<!-- 注解驱动 -->

<mvc:annotation-driven />

视图解析器

视图解析器使用SpringMVC框架默认的InternalResourceViewResolver,这个视图解析器支持JSP视图解析

在springmvc.xml配置文件中配置如下:

<!-- Example: prefix="/WEB-INF/jsp/", suffix=".jsp", viewname="test" ->

"/WEB-INF/jsp/test.jsp" -->

<!-- 配置视图解析器 -->

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<!-- 配置逻辑视图的前缀 -->

<property name="prefix" value="/WEB-INF/jsp/" />

<!-- 配置逻辑视图的后缀 -->

<property name="suffix" value=".jsp" />

</bean>

逻辑视图名需要在controller中返回ModelAndView指定,比如逻辑视图名为ItemList,则最终返回的jsp视图地址:

"WEB-INF/jsp/itemList.jsp"

最终jsp物理地址:前缀+逻辑视图名+后缀

修改ItemController

修改ItemController中设置视图的代码

// @RequestMapping:里面放的是请求的url,和用户请求的url进行匹配

// action可以写也可以不写

@RequestMapping("/itemList.action")

public ModelAndView queryItemList() {

// 创建页面需要显示的商品数据

List<Item> list = new ArrayList<>();

list.add(new Item(1, "1华为 荣耀8", 2399, new Date(), "质量好!1"));

list.add(new Item(2, "2华为 荣耀8", 2399, new Date(), "质量好!2"));

list.add(new Item(3, "3华为 荣耀8", 2399, new Date(), "质量好!3"));

list.add(new Item(4, "4华为 荣耀8", 2399, new Date(), "质量好!4"));

list.add(new Item(5, "5华为 荣耀8", 2399, new Date(), "质量好!5"));

list.add(new Item(6, "6华为 荣耀8", 2399, new Date(), "质量好!6"));

// 创建ModelAndView,用来存放数据和视图

ModelAndView modelAndView = new ModelAndView();

// 设置数据到模型中

modelAndView.addObject("itemList", list);

// 设置视图jsp,需要设置视图的物理地址

// modelAndView.setViewName("/WEB-INF/jsp/itemList.jsp");

// 配置好视图解析器前缀和后缀,这里只需要设置逻辑视图就可以了。

// 视图解析器根据前缀+逻辑视图名+后缀拼接出来物理路径

modelAndView.setViewName("itemList");

return modelAndView;

}

效果

效果和之前一样,如下图:

十分钟带你学会SpringMVC,就是这么简单

整合mybatis

为了更好的学习 springmvc和mybatis整合开发的方法,需要将springmvc和mybatis进行整合。

整合目标:控制层采用springmvc、持久层使用mybatis实现。

创建数据库表

sql脚本,位置如下图:

十分钟带你学会SpringMVC,就是这么简单

创建数据库表springmvc,导入到数据库中,如下图:

十分钟带你学会SpringMVC,就是这么简单

需要的jar包

1. spring(包括springmvc)

2. mybatis

3. mybatis-spring整合包

4. 数据库驱动

5. 第三方连接池。

jar包位置如下图:

十分钟带你学会SpringMVC,就是这么简单

整合思路

Dao层:

1、 SqlMapConfig.xml,空文件即可,但是需要文件头。

2、 applicationContext-dao.xml

a) 数据库连接池

b) SqlSessionFactory对象,需要spring和mybatis整合包下的。

c) 配置mapper文件扫描器。

Service层:

1、 applicationContext-service.xml包扫描器,扫描@service注解的类。

2、 applicationContext-trans.xml配置事务。

Controller层:

1、 Springmvc.xml

a) 包扫描器,扫描@Controller注解的类。

b) 配置注解驱动

c) 配置视图解析器

Web.xml文件:

1、 配置spring

2、 配置前端控制器。

创建工程

创建动态web工程springmvc-web,如下图:

十分钟带你学会SpringMVC,就是这么简单

十分钟带你学会SpringMVC,就是这么简单

加入jar包

复制jar包到/WEB-INF/lib中

工程自动加载jar包

加入配置文件

创建资源文件夹config

在其下创建mybatis和spring文件夹,用来存放配置文件,如下图:

十分钟带你学会SpringMVC,就是这么简单

sqlMapConfig.xml

使用逆向工程来生成Mapper相关代码,不需要配置别名。

在config/mybatis下创建SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

</configuration>

applicationContext-dao.xml

配置数据源、配置SqlSessionFactory、mapper扫描器。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"

xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<!-- 加载配置文件 -->

<context:property-placeholder location="classpath:db.properties" />

<!-- 数据库连接池 -->

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

<property name="driverClassName" value="${jdbc.driver}" />

<property name="url" value="${jdbc.url}" />

<property name="username" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

<property name="maxActive" value="10" />

<property name="maxIdle" value="5" />

</bean>

<!-- 配置SqlSessionFactory -->

<bean id="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean">

<!-- 数据库连接池 -->

<property name="dataSource" ref="dataSource" />

<!-- 加载mybatis的全局配置文件 -->

<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>

</bean>

<!-- 配置Mapper扫描 -->

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<!-- 配置Mapper扫描包 -->

<property name="basePackage" value="cn.itcast.ssm.mapper" />

</bean>

</beans>

db.properties

配置数据库相关信息

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/springmvc?characterEncoding=utf-8

jdbc.username=root

jdbc.password=root

applicationContext-service.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"

xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<!-- 配置service扫描 -->

<context:component-scan base-package="cn.itcast.ssm.service" />

</beans>

applicationContext-trans.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"

xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<!-- 事务管理器 -->

<bean id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<!-- 数据源 -->

<property name="dataSource" ref="dataSource" />

</bean>

<!-- 通知 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">

<tx:attributes>

<!-- 传播行为 -->

<tx:method name="save*" propagation="REQUIRED" />

<tx:method name="insert*" propagation="REQUIRED" />

<tx:method name="delete*" propagation="REQUIRED" />

<tx:method name="update*" propagation="REQUIRED" />

<tx:method name="find*" propagation="SUPPORTS" read-only="true" />

<tx:method name="get*" propagation="SUPPORTS" read-only="true" />

<tx:method name="query*" propagation="SUPPORTS" read-only="true" />

</tx:attributes>

</tx:advice>

<!-- 切面 -->

<aop:config>

<aop:advisor advice-ref="txAdvice"

pointcut="execution(* cn.itcast.ssm.service.*.*(..))" />

</aop:config>

</beans>

springmvc.xml

<?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:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<!-- 配置controller扫描包 -->

<context:component-scan base-package="cn.itcast.ssm.controller" />

<!-- 注解驱动 -->

<mvc:annotation-driven />

<!-- Example: prefix="/WEB-INF/jsp/", suffix=".jsp", viewname="test" ->

"/WEB-INF/jsp/test.jsp" -->

<!-- 配置视图解析器 -->

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<!-- 配置逻辑视图的前缀 -->

<property name="prefix" value="/WEB-INF/jsp/" />

<!-- 配置逻辑视图的后缀 -->

<property name="suffix" value=".jsp" />

</bean>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

id="WebApp_ID" version="2.5">

<display-name>springmvc-web</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

<!-- 配置spring -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/applicationContext*.xml</param-value>

</context-param>

<!-- 使用监听器加载Spring配置文件 -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- 配置SrpingMVC的前端控制器 -->

<servlet>

<servlet-name>springmvc-web</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/springmvc.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>springmvc-web</servlet-name>

<!-- 配置所有以action结尾的请求进入SpringMVC -->

<url-pattern>*.action</url-pattern>

</servlet-mapping>

</web-app>

加入jsp页面

复制课前资料的itemList.jsp和itemEdit.jsp到工程中

效果

配置完效果如下图:

十分钟带你学会SpringMVC,就是这么简单

实现商品列表显示

需求

实现商品查询列表,从mysql数据库查询商品信息。

DAO开发

使用逆向工程,生成代码

注意修改逆向工程的配置文件,参考MyBatis第二天

逆向工程生成代码如下图:

十分钟带你学会SpringMVC,就是这么简单

ItemService接口

public interface ItemService {

/**

* 查询商品列表

*

* @return

*/

List<Item> queryItemList();

}

ItemServiceImpl实现类

@Service

public class ItemServiceImpl implements ItemService {

@Autowired

private ItemMapper itemMapper;

@Override

public List<Item> queryItemList() {

// 从数据库查询商品数据

List<Item> list = this.itemMapper.selectByExample(null);

return list;

}

}

ItemController

@Controller

public class ItemController {

@Autowired

private ItemService itemService;

/**

* 显示商品列表

*

* @return

*/

@RequestMapping("/itemList")

public ModelAndView queryItemList() {

// 获取商品数据

List<Item> list = this.itemService.queryItemList();

ModelAndView modelAndView = new ModelAndView();

// 把商品数据放到模型中

modelAndView.addObject("itemList", list);

// 设置逻辑视图

modelAndView.setViewName("itemList");

return modelAndView;

}

}

测试

访问url:

http://127.0.0.1:8080/springmvc-web/itemList.action

效果如下图:

十分钟带你学会SpringMVC,就是这么简单

参数绑定

默认支持的参数类型

需求

打开商品编辑页面,展示商品信息。

需求分析

编辑商品信息,首先要显示商品详情

需要根据商品id查询商品信息,然后展示到页面。

请求的url:/itemEdit.action

参数:id(商品id)

响应结果:商品编辑页面,展示商品详细信息。

ItemService接口

编写ItemService接口如下图:

十分钟带你学会SpringMVC,就是这么简单

ItemServiceImpl实现类

@Override

public Item queryItemById(int id) {

Item item = this.itemMapper.selectByPrimaryKey(id);

return item;

}

ItemController

页面点击修改按钮,发起请求

http://127.0.0.1:8080/springmvc-web/itemEdit.action?id=1

需要从请求的参数中把请求的id取出来。

Id包含在Request对象中。可以从Request对象中取id。

想获得Request对象只需要在Controller方法的形参中添加一个参数即可。Springmvc框架会自动把Request对象传递给方法。

代码实现

/**

* 根据id查询商品

*

* @param request

* @return

*/

@RequestMapping("/itemEdit")

public ModelAndView queryItemById(HttpServletRequest request) {

// 从request中获取请求参数

String strId = request.getParameter("id");

Integer id = Integer.valueOf(strId);

// 根据id查询商品数据

Item item = this.itemService.queryItemById(id);

// 把结果传递给页面

ModelAndView modelAndView = new ModelAndView();

// 把商品数据放在模型中

modelAndView.addObject("item", item);

// 设置逻辑视图

modelAndView.setViewName("itemEdit");

return modelAndView;

}

默认支持的参数类型

处理器形参中添加如下类型的参数处理适配器会默认识别并进行赋值。

HttpServletRequest

通过request对象获取请求信息

HttpServletResponse

通过response处理响应信息

HttpSession

通过session对象得到session中存放的对象

Model/ModelMap

Model

除了ModelAndView以外,还可以使用Model来向页面传递数据,

Model是一个接口,在参数里直接声明model即可。

如果使用Model则可以不使用ModelAndView对象,Model对象可以向页面传递数据,View对象则可以使用String返回值替代。

不管是Model还是ModelAndView,其本质都是使用Request对象向jsp传递数据。

代码实现:

/**

* 根据id查询商品,使用Model

*

* @param request

* @param model

* @return

*/

@RequestMapping("/itemEdit")

public String queryItemById(HttpServletRequest request, Model model) {

// 从request中获取请求参数

String strId = request.getParameter("id");

Integer id = Integer.valueOf(strId);

// 根据id查询商品数据

Item item = this.itemService.queryItemById(id);

// 把结果传递给页面

// ModelAndView modelAndView = new ModelAndView();

// 把商品数据放在模型中

// modelAndView.addObject("item", item);

// 设置逻辑视图

// modelAndView.setViewName("itemEdit");

// 把商品数据放在模型中

model.addAttribute("item", item);

return "itemEdit";

}

ModelMap

ModelMap是Model接口的实现类,也可以通过ModelMap向页面传递数据

使用Model和ModelMap的效果一样,如果直接使用Model,springmvc会实例化ModelMap。

代码实现:

/**

* 根据id查询商品,使用ModelMap

*

* @param request

* @param model

* @return

*/

@RequestMapping("/itemEdit")

public String queryItemById(HttpServletRequest request, ModelMap model) {

// 从request中获取请求参数

String strId = request.getParameter("id");

Integer id = Integer.valueOf(strId);

// 根据id查询商品数据

Item item = this.itemService.queryItemById(id);

// 把结果传递给页面

// ModelAndView modelAndView = new ModelAndView();

// 把商品数据放在模型中

// modelAndView.addObject("item", item);

// 设置逻辑视图

// modelAndView.setViewName("itemEdit");

// 把商品数据放在模型中

model.addAttribute("item", item);

return "itemEdit";

}

绑定简单类型

当请求的参数名称和处理器形参名称一致时会将请求参数与形参进行绑定。

这样,从Request取参数的方法就可以进一步简化。

/**

* 根据id查询商品,绑定简单数据类型

*

* @param id

* @param model

* @return

*/

@RequestMapping("/itemEdit")

public String queryItemById(int id, ModelMap model) {

// 根据id查询商品数据

Item item = this.itemService.queryItemById(id);

// 把商品数据放在模型中

model.addAttribute("item", item);

return "itemEdit";

}

支持的数据类型

参数类型推荐使用包装数据类型,因为基础数据类型不可以为null

整形:Integer、int

字符串:String

单精度:Float、float

双精度:Double、double

布尔型:Boolean、boolean

说明:对于布尔类型的参数,请求的参数值为true或false。或者1或0

请求url:

http://localhost:8080/xxx.action?id=2&status=false

处理器方法:

public String editItem(Model model,Integer id,Boolean status)

@RequestParam

使用@RequestParam常用于处理简单类型的绑定。

value:参数名字,即入参的请求参数名字,如value="itemId"表示请求的参数 区中的名字为itemId的参数的值将传入

required:是否必须,默认是true,表示请求中一定要有相应的参数,否则将报错

TTP Status 400 - Required Integer parameter 'XXXX' is not present

defaultValue:默认值,表示如果请求中没有同名参数时的默认值

定义如下:

@RequestMapping("/itemEdit")

public String queryItemById(@RequestParam(value = "itemId", required = true, defaultValue = "1") Integer id,

ModelMap modelMap) {

// 根据id查询商品数据

Item item = this.itemService.queryItemById(id);

// 把商品数据放在模型中

modelMap.addAttribute("item", item);

return "itemEdit";

}

绑定pojo类型

需求

将页面修改后的商品信息保存到数据库中。

需求分析

请求的url:/updateItem.action

参数:表单中的数据。

响应内容:更新成功页面

使用pojo接收表单数据

如果提交的参数很多,或者提交的表单中的内容很多的时候,可以使用简单类型接受数据,也可以使用pojo接收数据。

要求:pojo对象中的属性名和表单中input的name属性一致。

页面定义如下图:

十分钟带你学会SpringMVC,就是这么简单

Pojo(逆向工程生成)如下图:

十分钟带你学会SpringMVC,就是这么简单

请求的参数名称和pojo的属性名称一致,会自动将请求参数赋值给pojo的属性。

ItemService接口

ItemService里编写接口方法

/**

* 根据id更新商品

*

* @param item

*/

void updateItemById(Item item);

ItemServiceImpl实现类

ItemServiceImpl里实现接口方法

使用updateByPrimaryKeySelective(item)方法,忽略空参数

@Override

public void updateItemById(Item item) {

this.itemMapper.updateByPrimaryKeySelective(item);

}

ItemController

/**

* 更新商品,绑定pojo类型

*

* @param item

* @param model

* @return

*/

@RequestMapping("/updateItem")

public String updateItem(Item item) {

// 调用服务更新商品

this.itemService.updateItemById(item);

// 返回逻辑视图

return "success";

}

注意:

提交的表单中不要有日期类型的数据,否则会报400错误。如果想提交日期类型的数据需要用到后面的自定义参数绑定的内容。

编写success页面

如下图创建success.jsp页面

十分钟带你学会SpringMVC,就是这么简单

页面代码:

<%@ 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; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<h1>商品修改成功!</h1>

</body>

</html>

解决post乱码问题

提交发现,保存成功,但是保存的是乱码

在web.xml中加入:

<!-- 解决post乱码问题 -->

<filter>

<filter-name>encoding</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<!-- 设置编码参是UTF8 -->

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encoding</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

以上可以解决post请求乱码问题。

对于get请求中文参数出现乱码解决方法有两个:

修改tomcat配置文件添加编码与工程编码一致,如下:

<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

另外一种方法对参数进行重新编码:

String userName new

String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")

ISO8859-1是tomcat默认编码,需要将tomcat编码后的内容按utf-8编码

绑定包装pojo

需求

使用包装的pojo接收商品信息的查询条件。

需求分析

包装对象定义如下:

public class QueryVo {

private Item item;

set/get。。。

}

页面定义如下图:

十分钟带你学会SpringMVC,就是这么简单

接收查询条件

// 绑定包装数据类型

@RequestMapping("/queryItem")

public String queryItem(QueryVo queryVo) {

System.out.println(queryVo.getItem().getId());

System.out.println(queryVo.getItem().getName());

return "success";

}

自定义参数绑定

需求

在商品修改页面可以修改商品的生产日期,并且根据业务需求自定义日期格式。

需求分析

由于日期数据有很多种格式,springmvc没办法把字符串转换成日期类型。所以需要自定义参数绑定。

前端控制器接收到请求后,找到注解形式的处理器适配器,对RequestMapping标记的方法进行适配,并对方法中的形参进行参数绑定。可以在springmvc处理器适配器上自定义转换器Converter进行参数绑定。

一般使用<mvc:annotation-driven/>注解驱动加载处理器适配器,可以在此标签上进行配置。

修改jsp页面

如下图修改itemEdit.jsp页面,显示时间

十分钟带你学会SpringMVC,就是这么简单

自定义Converter

//Converter<S, T>

//S:source,需要转换的源的类型

//T:target,需要转换的目标类型

public class DateConverter implements Converter<String, Date> {

@Override

public Date convert(String source) {

try {

// 把字符串转换为日期类型

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");

Date date = simpleDateFormat.parse(source);

return date;

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// 如果转换异常则返回空

return null;

}

}

配置Converter

我们同时可以配置多个的转换器。

类似下图的usb设备,可以接入多个usb设备

十分钟带你学会SpringMVC,就是这么简单

<!-- 配置注解驱动 -->

<!-- 如果配置此标签,可以不用配置... -->

<mvc:annotation-driven conversion-service="conversionService" />

<!-- 转换器配置 -->

<bean id="conversionService"class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

<property name="converters">

<set>

<bean class="cn.itcast.springmvc.converter.DateConverter" />

</set>

</property>

</bean>

配置方式2(了解)

<!--注解适配器 -->

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">

<property name="webBindingInitializer" ref="customBinder"></property>

</bean>

<!-- 自定义webBinder -->

<bean id="customBinder"class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">

<property name="conversionService" ref="conversionService" />

</bean>

<!-- 转换器配置 -->

<bean id="conversionService"class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

<property name="converters">

<set>

<bean class="cn.itcast.springmvc.convert.DateConverter" />

</set>

</property>

</bean>

注意:此方法需要独立配置处理器映射器、适配器,

不再使用<mvc:annotation-driven/>

springmvc与struts2不同

1、 springmvc的入口是一个servlet即前端控制器,而struts2入口是一个filter过滤器。

2、 springmvc是基于方法开发(一个url对应一个方法),请求参数传递到方法的形参,可以设计为单例或多例(建议单例),struts2是基于类开发,传递参数是通过类的属性,只能设计为多例。

3、 Struts采用值栈存储请求和响应的数据,通过OGNL存取数据, springmvc通过参数解析器是将request请求内容解析,并给方法形参赋值,将数据和视图封装成ModelAndView对象,最后又将ModelAndView中的模型数据通过request域传输到页面。Jsp视图解析器默认使用jstl。

【EPICS学习记录】根据官方教程创建一个IOC应用 参照官网给出的IOC创建教程逐步操作完成了一个IOC应用的创建,官网教程中有部分过程表述的不清晰,自己摸索之后完成了IOC的创建,并把流程记录下来。其中有一些操作不是很理解,有问题或者建议欢迎指正。 阅读详情

相关推荐

单目视觉定位:深入解析PNP算法在机器人导航中的实战应用

本文深入解析了PNP算法在机器人单目视觉定位中的核心原理与实战应用。通过拆解坐标变换四步,详细阐述了如何从二维图像点反求相机三维位姿。文章结合OpenCV的solvePnP函数,提供了算法选择、参数调优及结果后处理的实用指南,并针对机器人导航中的特征匹配、尺度不确定性等挑战,给出了鲁棒性优化与实时性平衡的解决方案。

weixin_29083649的博客 425

Spring Web MVC从入门到实战

本文全面讲解Spring Web MVC框架的核心知识与实战应用,从MVC设计模式原理入手,深入剖析Spring MVC的核心注解、请求响应处理机制、应用分层架构等关键内容。通过多个企业级实战项目(加法计算器、用户登录系统、图书管理系统),结合Postman、Lombok等开发工具,帮助开发者快速掌握Spring MVC在实际开发中的应用技巧。文章严格遵循企业开发规范,包含完整的代码示例、技术图表和权威参考链接,适合Java后端开发者从入门到精通Spring MVC框架,构建高质量的Web应用程序。

此人很懒,什么都留下了...快进来看看吧 4435

CAS5和CAS6自定义异常提示消息

CAS自定义异常提示消息

weixin_42949219的博客 981

SpringMVC(通俗易懂!!十分钟带你搭建第一个SpringMVC项目!!)

SpringMVC 先创建一个简单的Maven项目,添加WEB框架支持: 配置服务器: 参考我以前的博文:传送门–Tomcat和jetty服务器配置 代码主体内容: 导入依赖: <dependencies> <dependency> <groupId>org.springframework</groupId...

Pluto.的博客 581

DaVinci Developer中枚举类型变量的创建与实战应用

本文详细介绍了在DaVinci Developer中创建和使用枚举类型变量的方法与实战应用。通过智能温控系统的案例,阐述了枚举类型在嵌入式开发中的核心价值,包括提升代码可读性、类型安全性和维护便捷性。文章还提供了枚举类型在状态机实现和多模块协同中的高级应用技巧,以及调试与优化的实用建议。

ik678901234的博客 521

usb设备的定位信息获取

一个usb hub有20个口,每个口有一个标号,那么如果一个为X的标号插入了一个android设备,如何通过函数,得到这个X,代码实现如下,获取了location, 得到类似 Port_#0002.Hub_#0003 的字符串,然后,要对应一个表。

babytiger的专栏 2111

7天学完Spring:Spring MVC框架基础学习

冲!

weixin_53860901的博客 1120

MIPI D-PHY TX 一致性测试实例解析 Part 02

如果测过1.3.x,并对这组测试的细节已经熟悉的前提下,1.4.x的测试将会变得轻松,因为几乎相同的测试项被用于时钟通道的数据测量。

一只豌豆象的博客 8336

SpringMVC之六:Controller详细介绍

一、简介 在SpringMVC中,控制器Controller负责处理由DispatcherServlet分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model,然后再把该Model返回给对应的View进行展示。在SpringMVC中提供了一个非常简便的定义Controller的方法,你无需继承特定的类或实现特定的接口,只需使用@Controller标记一个类是Controller,然后使用@RequestMapping和@RequestParam...

weixin_42073629的博客 2453

4位无符号比较器设计

4位无符号比较器设计

好好学习,天天向上 7893

化工仿真软件:gPROMS二次开发_(1).gPROMS基础知识

在gPROMS中,模型是通过定义变量、参数和方程来创建的。模型可以是简单的单元操作,如换热器、反应器,也可以是复杂的系统,如整个化工流程。变量是模型中表示状态或输出的量。在gPROMS中,变量需要显式定义其类型和单位。# 定义变量VAR# 温度变量,单位为K# 压力变量,单位为Pa# 组分摩尔分数,数组变量参数是模型中表示常量或初始条件的量。参数同样需要定义其类型和单位。# 定义参数PAR# 理想气体常数,单位为J/(mol·K)# 反应器体积,单位为m^3# 初始摩尔数。

kkchenjj的博客 624

Spring MVC Controller介绍及常用注解

文章目录1、简介2、使用@Controller定义一个Controller控制器3、使用 @RequestMapping 来映射 Request 请求与处理器3.1 使用 URI 模板3.2 使用 @RequestParam 绑定 HttpServletRequest 请求参数到控制器方法参数3.3 使用 @CookieValue 绑定 cookie 的值到 Controller 方法参数3.4 使用 @RequestHeader 注解绑定 HttpServletRequest 头信息到Controller

温故而知新 1181

SAP 调用Ftp服务器

FTP(File transfer protocol)是一种标准的网络协议,可以用于在互联网上传递文件。SAP系统中可通过系列配置和提供的些标准函数,用于查看、更新、下载FTP服务器上的文件。提示:以下是本篇文章正文内容,下面案例可供参考。

qq_38304013的博客 1418

【SpringMVC】十分钟跑起来一个SpringMVC项目

springMVC

qq_53433382的博客 874

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

十分钟SpringMVC源码详解

谈谈SpringMVC的工作流程 用户发送请求到达前端控制器(DispatcherServlet); DispatcherServlet调用处理器映射器(HandlerMapping); 处理器映射器(HandlerMapping)找到具体的处理器执行链(HandlerExecutionChain); DispatcherServlet调用处理器适配器(handlerAdapter); 处理器适配器(handlerAdapter)经过适配后调用具体的处理器(handler); 具体处理器(handler)

零度念者的博客 349

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

十分钟带你轻松入门Shiro

首先集成Spring、SpringMVC和Shiro <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.18.RELEASE</version> </dependenc

yueyunyin的博客 346

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

springmvc默认方法名为映射名_SpringMVC学习要点--十分钟帮你快速掌握框架核心

《“爱读书”--给你讲技术》,我来看书,你来进步,让我们开始吧!本书简介书名为《Spring+MyBatis企业应用实战》,是本人在学习JavaEE框架时候的一本基础书籍,本书对于SpringMVC和MyBatis框架及相关基础知识讲述的比较清晰,适合需要详细学习Java框架的读者。本文内容为本书第二章--第八章,记录和总结了所有SpringMVC的知识DispatcherServlet1.Dis...

weixin_39771260的博客 171

十分钟带你了解Spring的七大知识点,程序员必了解

Spring框架自诞生以来一直备受开发者青睐,有人亲切的称之为:Spring 全家桶。它包括SpringMVC、SpringBoot、Spring Cloud、Spring Cloud Dataflow等解决方案。 很多研发人员把spring看作心目中最好的java项目,没有之一。 所以这是重点也是难点,工作中必须会,面试时肯定考。 那么,今天花费10分钟,梳理Spring框架相关知识。 免费的java资料需要的自己领取哦,私信小编位xuanwo013即可免费领取!!!(含玩转spring全家.

weixin_46794373的博客 313

十分钟就能回顾Spring常问的知识点,带你突击面试没问题!

本篇主要记录一些关于Spring的基础知识,(头铁的旁友随意)。

2401_84048832的博客 766

shiro 字段不是username 和password_十分钟带你轻松入门Shiro

首先集成Spring、SpringMVC和Shiroorg.springframeworkspring-context4.3.18.RELEASEorg.springframeworkspring-webmvc4.3.18....

weixin_39785165的博客 188

保姆级教程搭建SSM框架,十分钟亲手学会搭建企业级工程

关于Spring + Spring MVC + MyBatis的搭建 1.在IDEA界面中创建MavenWeb工程,选中下图maven-archetype-webapp 2.在pom.xml中添加如下相关依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-.

DrLai的博客 290

十分钟带你回顾Spring常问的知识点

前言 周末,天气放晴,玩的还挺开心,过后,我像往常一样坐在窗台,看着电脑“发呆”,就不给大家分享技术干货了。给大家整理一份面试清单总结吧,都是一些基础的题,是IT公司就喜欢考这些基础的东西,所以为了能进大公司就~当复习期末考吧。花了不少时间整理,在整理过程中也学到了很多东西,请大家认真对待每一题! Spirng IOC 1.Spring框架 2.Spring IOC 容器 Bean 对象实例化模拟 3.Spring IOC 配置文件加载 4.Spring IOC 容器 Bean 对象实例化 5.Spr

m0_57624732的博客 98

SpringMVC 常见面试题整理

本篇大概两千多字,预计阅读十分钟左右。 主要是对网上的一些常见问题进行收集整理,自己结合平时的项目中出现的一些问题的总结。如果大家在阅读过程中有什么疑问的地方可以一起交流讨论。 1. 什么是 SpringMVC ?说说你对 SpringMVC 的理解 SpringMVC 其实是基于 Spring 框架下的的 webmvc 模块发展而来的,底层的实现是 基于 Servlet API 的。 做到 M(Model)— V(View)— C(Controller)分层。降低各层次之间的耦合性,简化开发。 2. S

江璇Up 462
上一篇: 曾经一位行业大牛给予Java初学者的学习规划
下一篇: springMVC一个Controller处理所有用户请求的并发问题
pingdouble
博客等级 码龄15年 325粉丝 63原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址