spring整合mybatis错误:HTTP Status 404 - xxx-xxx....

本文介绍了一种常见的404错误及其解决方案,错误源于使用了错误的ModelAndView包,通过更正包引用解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  运行环境:jdk1.7.0_17 + tomcat 7 + spring 3.2.0 +mybatis 3.2.7+ eclipse,访问路径:http://localhost:8085/Springmvc_Mybits_store/queryItems.do

  错误: 导致404 错误,一般是转发路径写错误,还有是请求时候书写错误找不到Handler仔细检查路径是否写对,今天要讲的错误,也可以说是比较粗心的犯的错,但对于新手没法找出来,在路径对的情况下,我们访问404错误,并且地址打印出来也是对的。

  错误原因 :查看controller导入的包:原因就在這两个包,由于现在还不能充分解释,当时写的时候是自动注入的包,注入是import org.springframework.web.portlet.ModelAndView;这是错误根本原因,找了资料大体解释下这两个的区别,在这两个包里面的

  ModelAndView 里面内容都是一样的,这两个是为适用不同的环境。

    org.springframework.web.portlet.ModelAndView:是一个支持处理方法的返回类型:意味着spring有一个HandlerMethodReturnValueHandler实现(ModelAndViewMethodReturnValueHandler),它将接收类型的返回值ModelAndView并处理它

    org.springframework.web.servlet.ModelAndView:默认情况下没有注册的实现

  解决办法:删除原有的org.springframework.web.portlet.ModelAndView 导入org.springframework.web.servlet.ModelAndView

  错误代码:控制台无报错,页面404错误;

      

 发送请求的日志文件:

 1 DispatcherServlet with name 'springmvc' processing GET request for [/Springmvc_Mybits_store/queryItems.do]
 2 Looking up handler method for path /queryItems.do
 3 Returning handler method [public org.springframework.web.portlet.ModelAndView com.kjczwl.ssm.controller.ItemsController.queryItems() throws java.lang.Exception]
 4 Returning cached instance of singleton bean 'itemsController'
 5 Last-Modified value for [/Springmvc_Mybits_store/queryItems.do] is: -1
 6 Creating a new SqlSession
 7 Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
 8 Fetching JDBC Connection from DataSource
 9 Registering transaction synchronization for JDBC Connection
10 JDBC Connection [jdbc:mysql://localhost:3306/store, UserName=root@localhost, MySQL Connector Java] will be managed by Spring
11 ==>  Preparing: SELECT * from items 
12 ==> Parameters: 
13 <==      Total: 4
14 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
15 Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
16 Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7adc9dc9]
17 Returning JDBC Connection to DataSource
18 44444444444444444444444444444
19 Rendering view [org.springframework.web.servlet.view.JstlView: name 'queryItems'; URL [/WEB-INF/pages/items/queryItems.jsp]] in DispatcherServlet with name 'springmvc'
20 Added model object 'modelAndView' of type [org.springframework.web.portlet.ModelAndView] to request in view with name 'queryItems'
21 Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'queryItems'
22 Forwarding to resource [/WEB-INF/pages/items/queryItems.jsp] in InternalResourceView 'queryItems'
23 Successfully completed request

 

  相关代码:

     工程结构:

      

 controller 代码:

 1  1 package com.kjczwl.ssm.controller;
 2  2 
 3  3 import java.util.List;
 4  4 
 5  5 import org.springframework.beans.factory.annotation.Autowired;
 6  6 import org.springframework.stereotype.Controller;
 7  7 import org.springframework.web.bind.annotation.RequestMapping;
 8  8 import org.springframework.web.portlet.ModelAndView;
 9  9 import com.kjczwl.ssm.po.ItemsCustom;
10 10 import com.kjczwl.ssm.service.ItemsService;
11 11 
12 12 /**
13 13  *<p>package:  com.kjczwl.ssm.controller</p>
14 14  *<p>Description:商品的controller(Handler) </p> 
15 15  *<p>Company: Springmvc_Mybits_store</p>
16 16  *@author:         唐烈
17 17  * @date            2017下午5:30:58
18 18  */
19 19 @Controller// 注解模式开发Controller
20 20 public class ItemsController {
21 21     // 注入 从service 中取得数据
22 22     @Autowired
23 23     ItemsService itemsService;
24 24     
25 25     //注解扫描, 后面映射地址  可通过queryItems.action 访问
26 26     @RequestMapping("/queryItems.do")
27 27     public ModelAndView queryItems()throws Exception{
28 28         //得到数据
29 29         List<ItemsCustom> itemList = itemsService.findItemsList(null);
30 30         // 构造ModelAndView 
31 31         ModelAndView modelAndView = new ModelAndView("itemsList");
32 32         // 添加到内存区 外面直接“${} 条件表达式获取”
33 33         modelAndView.addObject("itemList",itemList);
34 34         //转发的路径 modelAndView.setViewName("itemsList");
35 35         return modelAndView;
36 36     }
37 37 }

 

springmvc 配置:

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans
 3        xmlns="http://www.springframework.org/schema/beans"
 4        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5        xmlns:p="http://www.springframework.org/schema/p"
 6        xmlns:context="http://www.springframework.org/schema/context"
 7        xmlns:mvc="http://www.springframework.org/schema/mvc"
 8         xmlns:tx="http://www.springframework.org/schema/tx"
 9         xmlns:aop="http://www.springframework.org/schema/aop"
10           xsi:schemaLocation="http://www.springframework.org/schema/beans 
11                                       http://www.springframework.org/schema/beans/spring-beans.xsd
12                                       http://www.springframework.org/schema/context
13                                     http://www.springframework.org/schema/context/spring-context-3.2.xsd
14                                     http://www.springframework.org/schema/mvc
15                                     http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
16                                     http://www.springframework.org/schema/tx
17                                     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
18                                     http://www.springframework.org/schema/aop
19                                     http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
20 <!-- =================================================================================== -->    
21     <!-- 自动扫描注解 -->
22     <context:component-scan base-package="com.kjczwl.ssm.controller">
23         <!-- 
24             只扫描你规定的:<context:include-filter type="annotation" expression=""/>
25             不扫描你规定的:<context:exclude-filter type="annotation" expression=""/>    
26          -->
27     </context:component-scan>
28 <!-- =================================================================================== -->
29     <!-- 注解驱动 
30         代替:
31                      处理器适配器
32             <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
33                     处理器映射器 
34             <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
35     -->
36     <mvc:annotation-driven/>
37 <!-- =================================================================================== -->
38     <!-- 视图解析器
39         前缀:prefix
40         后缀:suffix
41      -->
42      <mvc:default-servlet-handler/>
43     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
44         <property name="prefix" value="/WEB-INF/pages/items/"/>
45         <property name="suffix" value=".jsp"/>
46     </bean>
47 </beans>

转载于:https://www.cnblogs.com/tanglie/p/6679238.html

org.mybatis.spring.MyBatisSystemException: null at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:97) ~[mybatis-spring-3.0.3.jar:3.0.3] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439) ~[mybatis-spring-3.0.3.jar:3.0.3] at jdk.proxy2/jdk.proxy2.$Proxy82.selectList(Unknown Source) ~[na:na] at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-3.0.3.jar:3.0.3] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:119) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:84) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:152) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.7.jar:3.5.7] at jdk.proxy2/jdk.proxy2.$Proxy130.findZeroValueRecords(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-6.0.13.jar:6.0.13] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.0.13.jar:6.0.13] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.0.13.jar:6.0.13] at com.baomidou.dynamic.datasource.aop.DynamicDataSourceAnnotationInterceptor.invoke(DynamicDataSourceAnnotationInterceptor.java:57) ~[dynamic-datasource-spring-4.3.0.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.13.jar:6.0 int offset = 0; int size = 1000; List<ElectricityDataHis> list = new ArrayList<>(); IPage<ElectricityDataHis> records; do { Page<ElectricityDataHis> pages = new Page<>(offset, size); // 第1页,每页10条 records = hisService.findZeroValueRecords(pages); records.getRecords().stream().forEach(record->{ // 获取前一个有效值 ElectricityDataHis lastValid = hisService.findLastValidBeforeTime( record.getTagId(), record.getRecordTime() ); if (lastValid != null) { // 生成修正后的新记录 record.setRecordValue(lastValid.getRecordValue()); record.setStatus(2);// 标记为已修正 // 写入修正记录(保留原始记录) list.add(record); } }); hisService.fixAllData(list); list.clear(); offset++; } while (! records.getRecords().isEmpty()); }
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值