直接在浏览器访问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";
}
}