SpringMVC之Controler层开发

SpringMVC之Controler层开发

controler层作用:

  • 根据前端请求(url)从后端找到对应的资源进行显示(或业务操作逻辑进行操作),将view层和model层串联起来的“桥梁”。

步骤:

  • 根据需求设计需要的URL(根据Restful规范)
  • 配置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: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.xsd
	http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	
	<!-- 配置spring mvc -->
<!--1,开启springmvc注解模式
    a.自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter
    b.默认提供一系列的功能:数据绑定,数字和日期的format@NumberFormat,@DateTimeFormat
    c:xml,json的默认读写支持-->
	<mvc:annotation-driven></mvc:annotation-driven>
	
	<!--2.静态资源默认servlet配置-->
    <!--
        1).加入对静态资源处理:js,gif,png
        2).允许使用 "/" 做整体映射
    -->
    <mvc:default-servlet-handler></mvc:default-servlet-handler>
    
    <!--3.配置JSP 显示ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
    	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    	<property name="prefix" value="/WEB-INF/jsp/"/>
    	<property name="suffix" value=".jsp"/>
    </bean>
    
    <!-- 4.扫描web相关的controller -->
    <context:component-scan base-package="cn.xiaofang.web"></context:component-scan>
</beans>
  • 对每个URL地址设计方法,调用指定的service层的函数
  • 使用Spring MVC注解方式来给方法指定对应的URL(@RequestMapping()、@ResponseBody)

控制层设计技巧:

  • Restful接口运用(规范设计URL)
  • SpringMVC使用技巧(通过注解实现URL与静态资源和业务方法之间的映射)
  • 前端交互分析过程

细节:

应用的概念介绍:

  • Restful
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值