在搭建开始前说明下,springmvc是由培训机构炒起来的一个框架,对于不少中小型公司来讲是不得不用的一个框架,但我以为一个有经验的后端工程师是不该该使用这种过分设计的框架.web
首先随便新建一个后端项目 而后右键选择 Configure faces..->install spring facetspring
进入该界面后端
next,把前两个复选框去掉spring-mvc
把一下代码放到web.xml下的display-namebash
<filter>
<filter-name>spring3encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>spring3encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>spring3</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring3</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
复制代码
添加spring3-servlet.xml文件到WEB-INF下mvc
<?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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
default-autowire="byName">
<!-- 描述包含controller的包路径, 以逗号分隔 -->
<context:component-scan base-package="my" > </context:component-scan>
<!-- 默认的注解映射的支持 -->
<mvc:annotation-driven />
<!-- 视图解释类 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp"/><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean>
<!-- 对静态资源文件的访问 方案一 (二选一) -->
<mvc:default-servlet-handler/>
</beans>
复制代码
须要注意的是控制器的包名我填的是my,也就是要在my包下写接口 另外xml的前面的名字要和web。xml里的servlet名字相同,若是不明白的话就直接复制粘贴app
好了项目终于初始化彻底了,如今新建一个my包写个“hello world”接口框架
运行结果jsp
成功,喵喵😄url