https://www.cnblogs.com/Feiyang-Lafe/p/6874122.html
我是参照这个的
我生成的war包名spring-mvc-study-Y
用下面的url可以登录进去
http://localhost:8080/spring-mvc-study-Y/courses/view2/123
传到了哪里?
这里的course对象内容被传入request的attribute里(可以把request想象成一个袋子),request得到内容后被return到前台页面,这一步是由SpringMVC帮我们完成的,最后前台使用EL表达式(如${course.title})取出数据。
希望能帮到你,谢谢。
除了不需要pox.xml配置,其余配置不变,然后自己导入jar到lib,部署tomcat
JSON数据
看图......
<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> //设置热加载 <contextReloadable>true</contextReloadable> </configuration> </plugin> </plugins>
在build中添加以上。
<?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 "> <!-- 本配置文件是共名为mvc-dispatcher的DispatcherServlet使用,提供其相关的Spring MVC配置 --> <!--启用Spring基于annotation的DI,使用户可以在Spring MVC中使用Spring的强大功能 激活@Required @Autowired,JSR 250's @PostConstruct,@PreDestroy and @Resource 等标注 --> <context:annotation-config /> <!-- DispatcherServlet上下文,只管理@Controller类型的bean,忽略其他标类型的bean,例如@Service --> <context:component-scan base-package="com.catcher92.mvcdemo"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- handlerMapping,无需配置,SpringMVC可以默认启动。 DefaultAnnotationHandlerMapping annotation-driven HandlerMapping --> <!-- 扩充了注解驱动,可以将请求参数绑定到控制器参数 --> <mvc:annotation-driven /> <!-- 静态资源处理,css,js,img --> <mvc:resources location="/resources/" mapping="/resources/**" /> <!-- 配置ViewResolver。 可以用多个ViewResolver。 使用order属性排序。 InternalResourceViewResolver放在最后。 --> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="1" /> <property name="mediaTypes"> <map> <entry key="json" value="application/json"></entry> <entry key="xml" value="application/xml"></entry> <entry key="htm" value="application/html"></entry> </map> </property> <property name="defaultViews"> <list> <!-- JSON View --> <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"></bean> </list> </property> <property name="ignoreAcceptHeader" value="true" /> </bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsps/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 200*1024*1024即200M resolveLazily属性启用是为了推迟文件解析,以便捕获文件大小异常 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="209715200" /> <property name="defaultEncoding" value="UTF-8" /> <property name="resolveLazily" value="true" /> </bean> </beans>
直接粘贴进去,然后改改base-package为你的试试看,如果还有问题用浏览器打开http://www.springframework.org/schema/mvc/spring-mvc.xsd看能否打开。
不用,tomcat启动也是一样的,maven一样可以使用,我就是用tomcat,右键属性看看有没有Maven依赖,没有就加上
直到了反正就是靠变量名本身
比如 /view2/{courseId}/{roleId}
那么对应的方法可能是这样
public String viewCourse2(@PathVariable Integer courseId,@PathVariable Integer roleId, Map<String, Object> model){
不仅是log.debug()、spring的打印日志也输出了两次。这是因为老师的log4j的配置的问题。在log4j.properties中找到如下两行,将
log4j.logger.com.imooc.mvcdemo=debug, Cons
log4j.logger.org.springframework=debug, Cons
后面的Cons去掉,即改成如下形式
log4j.logger.com.imooc.mvcdemo=debug
log4j.logger.org.springframework=debug
因为rootlogger配置成打印info级别的日志,已经打印过一次了。后面配置Cons相当于配置了rootlogger的子节点再打印一次
maven中央库有依赖代码,复制粘贴过来即可。老师的那个是为了节省时间,过滤掉了复制的过程。
http://www.dadiwin7.com/jc/3093.html 大家自行更改cmd的背景吧
Binding
说明你的URL没能找到正确的controller来处理