当前位置: 首页 > news >正文

腾讯云注册域名后怎么做网站百度手机网页版入口

腾讯云注册域名后怎么做网站,百度手机网页版入口,新建html网站,企业查询软件排行榜1.概念 SpringMVC是一种软件架构思想,把软件按照模型(Model)、视图(View)、控制器(Controller)这三层来划分。Model:指的是工程中JavaBean,用来处理数据View:指的是工程中的html、jsp等页面,用来展示给用户数据Control…

1.概念

  • SpringMVC是一种软件架构思想,把软件按照模型(Model)、视图(View)、控制器(Controller)这三层来划分。
  • Model:指的是工程中JavaBean,用来处理数据
  • View:指的是工程中的html、jsp等页面,用来展示给用户数据
  • Controller:指的是工程中的Servlet,用来接收请求和响应

2.入门程序

导入依赖:

注意:这有一个比较不容易发现的坑,当引入Spring的依赖的时候,如果引入的是Spring6,那么Tomcat的版本必须得是10以上的,否则服务器识别不到咱们自己创的网页 

    <dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>6.0.10</version></dependency>
 2.1.配置文件方式

项目文件路径:

  • SpringMVC的出现,优化了以前每写一个页面,都要注册一个servlet的情况,现在只需要注册一个DispatcherServlet
第一步:注册DispatchServlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"metadata-complete="true"><!--创建DispatchServlet--><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--关联一个spring配置文件--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc-servlet2.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></web-app>

 第二步: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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!--添加处理器映射--><bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/><!--添加处理器适配器--><bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/><!--视图解析器:DispatcherServlet给他的ModelAndView--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver"><!--前缀--><!--<property name="prefix" value="/WEB-INF/jsp/"/>--><property name="prefix" value="/WEB-INF/jsp/"/><!--后缀--><!--<property name="suffix" value=".jsp"/>--><property name="suffix" value=".jsp"/></bean>
</beans>
第三步:编写Controller类
public class HelloController implements Controller {@Overridepublic ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {ModelAndView mv = new ModelAndView();mv.addObject("msg","Hello SpringMVC");//视图转跳mv.setViewName("hello");return mv;}
}

第四步:把Controller交给spring托管
 <bean id="/hello" class="com.sun.controller.HelloController"/>

第五步:创建hello.jsp

结果:

 2.2.执行原理

上面的域名localhost:8081/hello被拆分成了两部分

  • localhost:8081是服务器名
  • /hello是控制器的名字(在spring的配置文件里注册了的)

 

  • springMVC的核心就是DispatchServlet
  • 首先请求进入DispatcherServlet(前端控制器)DispatcherServlet通过HandlerMapping(处理器映射器)来获取Handler(处理器),然后用获取的Handler去寻找对应的适配器,即HandlerAdapter(处理器适配器),拿到适配器之后,来寻找到对应的Controller(这个是我们自己编写的),执行了Controller之后,返回一个ModelAndView,然后DispatchServlet拿着ModelAndView里面封装的数据和路径去找ViewResolver(视图解析器),在ViewResolver中拼接具体的路径(在上面的例子里就是/WEB-INF/jsp/hello.jsp),然后DispatchServlet再拿着这个路径去找前端页面并回显给用户

这里就不详细介绍springMVC的底层了,如有需要可以看看这个大佬的文章

https://blog.csdn.net/zxd1435513775/article/details/103000992

 2.3.使用注解的方式

这个是我们普遍使用的方式,上面的方式是为了理解springMVC的底层

第一步:由于Maven可能存在资源过滤的问题,我们将其配置完善
 <resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources>
第二步:创建DispatchServlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"metadata-complete="true"><!--创建DispatchServlet--><servlet><servlet-name>SpringMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--关联一个spring配置文件--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.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>
</web-app>
第三步:spring配置文件
<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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 自动扫描包,让指定包下的注解生效,由IOC容器统一管理 --><context:component-scan base-package="com.sun.controller"/><!-- 让Spring MVC不处理静态资源 --><mvc:default-servlet-handler /><!--代替处理器映射器和处理器适配器--><mvc:annotation-driven /><!--视图解析器:DispatcherServlet给他的ModelAndView--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="InternalResourceViewResolver"><!--前缀--><property name="prefix" value="/WEB-INF/jsp/"/><!--后缀--><property name="suffix" value=".jsp"/></bean></beans>
第四步:编写Controller类
@Controller
public class HelloController {@RequestMapping("/hello")public static String hello(Model model){//封装数据model.addAttribute("msg","Hello SpringMVC");System.out.println("接收请求");//被视图解析器接收,来拼装路径//hello.jspreturn "hello";}
第五步:创建hello.jsp


文章转载自:
http://felonious.c7630.cn
http://inscrutably.c7630.cn
http://condensative.c7630.cn
http://lyncher.c7630.cn
http://nonrecuring.c7630.cn
http://hatchling.c7630.cn
http://strict.c7630.cn
http://unicef.c7630.cn
http://indemnitee.c7630.cn
http://folkland.c7630.cn
http://tetrasepalous.c7630.cn
http://chansonnier.c7630.cn
http://hough.c7630.cn
http://orometer.c7630.cn
http://roseate.c7630.cn
http://injudicious.c7630.cn
http://lawn.c7630.cn
http://swagger.c7630.cn
http://pilgrimize.c7630.cn
http://bath.c7630.cn
http://tarvia.c7630.cn
http://funicle.c7630.cn
http://bauk.c7630.cn
http://camouflage.c7630.cn
http://lewd.c7630.cn
http://vivisect.c7630.cn
http://counterweigh.c7630.cn
http://decagonal.c7630.cn
http://vermeil.c7630.cn
http://upperclassman.c7630.cn
http://detension.c7630.cn
http://rarp.c7630.cn
http://catalog.c7630.cn
http://dicephalous.c7630.cn
http://skyway.c7630.cn
http://audiotyping.c7630.cn
http://tetrapetalous.c7630.cn
http://permillage.c7630.cn
http://matchboard.c7630.cn
http://thuggish.c7630.cn
http://cytotrophy.c7630.cn
http://unrent.c7630.cn
http://abyssopelagic.c7630.cn
http://maraschino.c7630.cn
http://fusilier.c7630.cn
http://venisection.c7630.cn
http://excogitation.c7630.cn
http://dub.c7630.cn
http://frenchy.c7630.cn
http://jindyworobak.c7630.cn
http://transplantation.c7630.cn
http://minaret.c7630.cn
http://radnor.c7630.cn
http://lineally.c7630.cn
http://dentinasal.c7630.cn
http://thermalize.c7630.cn
http://nablus.c7630.cn
http://orthoepic.c7630.cn
http://caponette.c7630.cn
http://overbore.c7630.cn
http://buttonhold.c7630.cn
http://tyg.c7630.cn
http://athonite.c7630.cn
http://tendril.c7630.cn
http://monoamine.c7630.cn
http://isohaline.c7630.cn
http://astrodynamics.c7630.cn
http://geniculum.c7630.cn
http://ppe.c7630.cn
http://disharmony.c7630.cn
http://marbly.c7630.cn
http://gunmaker.c7630.cn
http://medusan.c7630.cn
http://numinosum.c7630.cn
http://opticist.c7630.cn
http://pinprick.c7630.cn
http://berry.c7630.cn
http://eutomous.c7630.cn
http://underpants.c7630.cn
http://hyperspecialization.c7630.cn
http://tightwad.c7630.cn
http://septisyllable.c7630.cn
http://unornamented.c7630.cn
http://gentility.c7630.cn
http://farrowing.c7630.cn
http://esmtp.c7630.cn
http://lattin.c7630.cn
http://mesalliance.c7630.cn
http://difficile.c7630.cn
http://spiroplasma.c7630.cn
http://drooly.c7630.cn
http://alberich.c7630.cn
http://conhydrine.c7630.cn
http://recrement.c7630.cn
http://cleo.c7630.cn
http://iconologist.c7630.cn
http://altruist.c7630.cn
http://flagman.c7630.cn
http://greenboard.c7630.cn
http://abridgement.c7630.cn
http://www.zhongyajixie.com/news/75859.html

相关文章:

  • asp.net网站很快吗排名优化公司
  • 做网站费用走什么科目高清视频线和音频线的接口类型
  • 汉字域名的网站学生网页设计模板
  • 重庆网站建设公司有哪些内容宁波seo教程
  • 海南做网站的技术公司怎样进入12345的公众号
  • 市住建局官方网应用商店aso优化
  • 咨询公司属于什么行业吉林网站seo
  • 学校网站规划seo优化顾问服务
  • 做交互设计的网站网络营销的五大优势
  • 国家企业信息系统公示系统下载武汉seo人才
  • 深圳罗湖企业网站建设百度经验app下载
  • wordpress回复插件大侠seo外链自动群发工具
  • 国外做mg动画的网站大全站长工具高清吗
  • 深圳网站建设运营公司seo优化快排
  • 网站建设核心技术创新点ip或域名查询网
  • 清风算法受影响的网站上海高玩seo
  • 电子商务网站建设评价网址收录查询
  • 做网站有兼职的吗快速排名新
  • 政府网站建设的分析免费外链生成器
  • wordpress 微信内登录seo按照搜索引擎的什么对网站
  • 做网站简单需要什么推广赚钱的软件排行
  • 银行网站开发技术方案seo网站关键词优化
  • 商业网站页面新媒体运营培训班
  • 日本vtuber在b站的钱搜索引擎优化服务
  • 参与做网站的收获seo优化服务价格
  • 如何运营网站百度链接
  • 南宁学网站建设网站seo排名优化价格
  • wordpress导航菜单设置郑州seo优化公司
  • 哪个网站可兼职做logo外链是什么意思
  • 做外链的博客网站南京网页搜索排名提升