这是报错信息 EmployeeDaoMapper.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.hp.pfm.edibleOil.dao.EmployeeDao"> <select id="selectListMap" parameterType="java.util.Map" resultMap="EmployeeMap"> <include refid="page.startPageSql"/> <include refid="SelectEmployeeList"/> <include refid="page.endPageSql"/> </select> <select id="selectCount" parameterType="java.util.Map" resultType="Long" > <include refid="page.startPageSql"/> <include refid="SelectEmployeeList"/> <include refid="page.endPageSql"/> </select> <sql id="SelectEmployeeList"> SELECT p.user_prc, p.pimage, t.tname, t.tjob, e.content, e.startlevel FROM PORT_USER_INFO p, TDEPT t, EMPLOYEE e WHERE p.td_id = t.td_id and p.user_id = e.user_id ORDER BY e.startlevel </sql> <resultMap id="EmployeeMap" type="java.util.Map"> <result property="EMPID" column="EMP_ID" jdbcType="INTEGER" javaType="int"></result> <result property="CONTENT" column="CONTENT" jdbcType="VARCHAR" javaType="java.lang.String"></result> <result property="STARTLEVEL" column="STARTLEVEL" jdbcType="INTEGER" javaType="int"></result> <result property="SORT" column="SORT" jdbcType="VARCHAR" javaType="java.lang.String"></result> <result property="USERID" column="USER_ID" jdbcType="INTEGER" javaType="int"></result> </resultMap> </mapper> EmployeeServiceImpl package com.hp.pfm.edibleOil.service.implement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.jws.WebService; import javax.servlet.http.HttpServlet; import org.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; import net.sf.json.JsonConfig; import net.sf.json.util.CycleDetectionStrategy; import com.hp.pfm.edibleOil.common.DateJsonValueProcessor; import com.hp.pfm.edibleOil.common.Pagination; import com.hp.pfm.edibleOil.dao.EmployeeDao; import com.hp.pfm.edibleOil.domain.Questions; import com.hp.pfm.edibleOil.service.EmployeeService; @SuppressWarnings("restriction") @WebService(targetNamespace="http://service.edibleOil.pfm.hp.com/",endpointInterface="com.hp.pfm.edibleOil.service.EmployeeService" ,serviceName="EmployeeService") public class EmployeeServiceImpl implements EmployeeService { private EmployeeDao employeeDao; public EmployeeDao getEmployeeDao() { return employeeDao; } public void setEmployeeDao(EmployeeDao employeeDao) { this.employeeDao = employeeDao; } public String getEmployeeList(String pageNum, String pageSize) { Map<String, Object> map = new HashMap<String, Object>(); List<Map<String, Object>>pageLists=new ArrayList<Map<String, Object>>(); Map<String, Object> pageMaps = new HashMap<String, Object>(); JsonConfig jf = new JsonConfig(); jf.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss")); //构造Pagination Pagination<Questions> pagination = new Pagination<Questions>(Integer.parseInt(pageNum), Integer.parseInt(pageSize),null); Pagination<Map> pageinfoMaps=new Pagination<Map>(Integer.parseInt(pageNum), Integer.parseInt(pageSize)); pageinfoMaps.setResult(employeeDao.selectListMap(pagination.getSqlParam())); pageinfoMaps.setCount(employeeDao.selectCount(pagination.getSqlParam())); //计算总页数 pageMaps.put("PAGENUM", pageNum); int totalPageNum = (int) ((pageinfoMaps.getCount() + Integer.parseInt(pageSize) - 1)/Integer.parseInt(pageSize)); pageMaps.put("PAGECOUNT", totalPageNum); pageLists.add(pageMaps); map.put("page", pageLists); map.put("result", "0"); map.put("data", pageinfoMaps.getResult()); System.out.println(JSONSerializer.toJSON(map,jf).toString()); return JSONSerializer.toJSON(map,jf).toString(); } } dao方法 public List<Map> selectListMap(Map param) { SqlSession session = null; List<Map> list = null; try { session = getSqlSession(); GenericDao<T> dao = session.getMapper(clazz); list = dao.selectListMap(param); } catch (Exception e) { log.error(e); } return list; } public long selectCount(Map param){ long count= 0; SqlSession session = null; try { session = getSqlSession(); GenericDao<T> dao = session.getMapper(clazz); count = dao.selectCount(param); } catch (Exception e) { e.printStackTrace(); log.error(e); } return count; } 错误信息是 java类型和数据库类型不匹配, 可是我都对比了几次 也没发现问题。 sql 数据能查询出来。 |
|
10分 |
“java.sql.SQLException: 无法转换为内部表示”很可能是因为数据库某字段的类型出错了,如:
数据库中的类型写的是varchar类型的,而在实体类中,写的是int类型 |
10分 |
楼主对比一下 你的model和数据库表的类型吧
|
我都对比N次了。。。 查询所有数据的时候不报错, 查询总条数的时候就报这个错,但是都用的一个sql呀。 我想应该是返回总条数的 类型 错了。。但是也找不到错啊 |
|
20分 |
你把查询出来的总数用long接收,不要 用int |
额 xml的返回类型和 java返回类型都是用的long啊 没有用int… |