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

    评论

报告相同问题?

悬赏问题

  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作