您现在的位置是:首页 > 文章详情

三层架构、Mvc配置

日期:2019-07-10点击:407

三层架构好处将每个部分都独立开,方便升级扩展

三层架构

 数据层 1.负责所有对象数据操作的方法 2.对数据连接处理 3.对外绝对不暴露任何sql语句 业务层 1.事务处理 2.业务处理 视图层 mvc结构 M 与业务层接轨处 C 控制器 V JSP数据呈现 MVC: 模型 M 业务调用,业务层调用 控制器 C 接受请求找到模型,得到模型结果,跳转至相应页面 视图 v 呈现数据 

请求过程 1、V>>>C>>>M>>>C>>>V 这个常用 因为所有都是由控制器来操作 视图不和逻辑交互

 2、 V>>>C>>>M>>>V 

引包:

springmvc springcontext javax.servlet javax.servlet.jsp.jstl javax.servlet.jsp 
 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.1.3.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.1.3.RELEASE</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency>

配置resources
Application.xml(名字自己随便起)

<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"> <context:annotation-config/> <!--开启注解模式--> <context:component-scan base-package="com.sun"/> <!--管理对象路径--> <mvc:annotation-driven/> <!--开启MVC注解模式--> </beans>
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @Controller //所明这个类是控制器 要想管理servlet就得将他们集中起来进行统一的管理 public class Action { @RequestMapping("/hello")//和webServlet作用一样 public void Method(int password, String uname, HttpServletRequest request, HttpServletResponse response, HttpSession session) { //这里获得的是 HttpServletRequest请求头,HttpServletResponse响应头 //servlet 有的都可以获得 // 表单获得变得简单 说明类型 及名称就可以获得表单数据 } } 
原文链接:https://yq.aliyun.com/articles/708595
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章