一个智子 2017-07-17 13:49 采纳率: 75%
浏览 5139
已结题

java.lang.NumberFormatException: For input string

直接在浏览器访问tolist.do,这是一个列出数据库帖子的请求,测试可以查询获取到pList中,但是执行controller中的model.addAttribute("pList", pList);这句就会报错,注释掉就没有报错。
求大神解答,万分感谢!!!

报错信息:
图片说明

还有debug信息:

 DEBUG [http-bio-8080-exec-3] - Rendering view [org.springframework.web.servlet.view.InternalResourceView: unnamed; URL [index.jsp]] in DispatcherServlet with name 'springmvc'
DEBUG [http-bio-8080-exec-3] - Added model object 'pList' of type [java.util.ArrayList] to request in view with name 'null'
DEBUG [http-bio-8080-exec-3] - Forwarding to resource [index.jsp] in InternalResourceView 'null'
七月 17, 2017 9:36:36 下午 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "title"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)

mapper.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="cn.edu.mapper.PostMapper">
    <resultMap type="post" id="postResult">
        <id property="id" column="pid"></id>
    </resultMap>
    <insert id="insert" parameterType="post" useGeneratedKeys="true" keyProperty="id">
        insert into t_post values(null,#{title},#{author},#{content},now())
    </insert>
    <select id="findAll" resultMap="postResult">
        select * from t_post 
    </select>
    <select id="findById" parameterType="Integer" resultMap="postResult">
        select * from t_post where pid = #{id}
    </select>
    <select id="findByTitle" parameterType="String" resultMap="postResult">
        select * from t_post where title = #{title}
    </select>
</mapper>

service

 package cn.edu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.mapper.CommentMapper;
import cn.edu.mapper.PostMapper;
import cn.edu.pojo.Comment;
import cn.edu.pojo.Post;
import cn.edu.pojo.PostComment;

@Service
public class PostServiceImpl implements PostService {
    @Autowired
    private PostMapper postMapperImpl;
    @Override
    public String insert(Post post) {
        Integer id = postMapperImpl.insert(post);
        String msg = "1";
        System.out.println(id);
        if(id == null){
            msg = "0";
        }
        return msg;
    }

    @Override
    public List<Post> findAllPosts() {
        return postMapperImpl.findAll();

    }

}

controller

 package cn.edu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.pojo.Comment;
import cn.edu.pojo.Post;
import cn.edu.service.PostService;

@Controller
public class PostController {
    @Autowired
    private PostService postServiceImpl;

    @RequestMapping("tolist")
    public String toList(Model model){
        List<Post> pList = postServiceImpl.findAllPosts();
        model.addAttribute("pList", pList);
        return "forward:index.jsp";
    }

}
  • 写回答

4条回答 默认 最新

  • ps45221 2017-07-18 00:56
    关注

    title格式错误,检查数据库、pojo、mapper、jsp中的类型
    此外forward:index.jsp这个写法好像有问题,找资料确认下

    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备