网站备案的幕布,佛山便宜网站建设,wordpress 分类 php,简单网页html模板一.Mvc#xff1a;
1.概念#xff1a;
MVC它是一种设计理念。把程序按照指定的结构来划分: Model模型 、View视图 、Controller控制层#xff1b; 结构图#xff1a; 二.Springmvc:
1.概念#xff1a;
springmvc框架它是spring框架的一个分支。它是按照mvc架构思想设计…一.Mvc
1.概念
MVC它是一种设计理念。把程序按照指定的结构来划分: Model模型 、View视图 、Controller控制层 结构图 二.Springmvc:
1.概念
springmvc框架它是spring框架的一个分支。它是按照mvc架构思想设计的一款框架。。springmvc的主要作用: 接收浏览器的请求数据对数据进行处理然后返回页面进行显示. 2.为什么学springmvc? 3.如何使用springmvc?⭐
准备工作创建一个maven的web工程 第一步在创建好的maven的web工程中把依赖引入 dependencies !--springmvc依赖-- dependency groupIdorg.springframework/groupId artifactIdspring-webmvc/artifactId version5.2.15.RELEASE/version /dependency /dependencies 第二步创建springmvc配置文件 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd!--第二步springmvc的配置文件--!--包扫描 扫描的是Controller 和 RequestMapping扫描范围扫描指定的包和子包可以到com.zyl--context:component-scan base-packagecom.zyl.controller/!--开启注解驱动--mvc:annotation-driven/!--放行静态资源--mvc:default-servlet-handler/!--视图解析器--bean classorg.springframework.web.servlet.view.InternalResourceViewResolver
!--前缀--property nameprefix value/views//!--后缀--property namesuffix value.jsp//bean/beans 第三步注册公共的servlet ---[DispatcherServlet]这里注意web.xml版本太低不行需要替换掉之前的4.0版本。看着改 ?xml version1.0 encodingUTF-8?
web-app xmlnshttp://xmlns.jcp.org/xml/ns/javaeexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsdversion4.0welcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-list
!--第四步 注册公共的servlet-DispatcherServlet--!--注册公共servlet--
servletservlet-namespring01/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-class!--加载 读取 spring 配置文件--init-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring01.xml/param-value/init-param
/servletservlet-mappingservlet-namespring01/servlet-name!--访问任何路径都要经过servlet--url-pattern//url-pattern/servlet-mapping/web-app 第四步.编写controller类 基本完成搭建框架步骤
springmvc的流程 * 1. 客户端发生请求http://localhost:8080/hello/index * 2. 来到tomcat服务器。 * 3. springmvc的前端控制器DipatcherServlet接受所有的请求。 * 4. 查看你的请求地址和哪个RequestMaping匹配。 * 5. 执行对应的方法。方法会返回一个字符串。 * 6. 把该字符串经过视图解析器拼接。 /前缀/字符串.后缀 * 7. 拿到拼接的地址找到对应的网页。 /views/hello.jsp * 8. 渲染该网页给客户
三、处理静态资源
静态资源就是网页中见到: js,css,image,html都是静态资源。 四、 接受参数
1. 接受少量参数
删除操作---值传递id. 2.接受大量参数 添加操作 修改操作。应该封装一个实体类。必须保证实体类的属性要和参数的名字一致。 封装一个实体类就行了 五、 解决乱码
只能使用过滤器。
1.自己编写过滤器 package com.zyl.filter;import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;/*** className: MyFilter* author: Zyl* date: 2024/12/14 15:04* Version: 1.0* description:*/
WebFilter(urlPatterns /*)
public class MyFilter implements Filter {Overridepublic void init(FilterConfig filterConfig) throws ServletException {System.out.println(过滤器初始化);}Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {servletResponse.setCharacterEncoding(UTF-8);servletRequest.setCharacterEncoding(UTF-8);filterChain.doFilter(servletRequest,servletResponse);}Overridepublic void destroy() {}
} 注意使用过滤器需要引入依赖 加上jdk8的代码吧后期好找 !--使用jdk8版本的--
propertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding
/properties 六、 处理日期参数
这个比较简单就在实体类里面加一个属性就可以了然后加上注解