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

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这个写法好像有问题,找资料确认下

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?