处理类
@Controller("wordsHandler")
@RequestMapping("words")public class WordsHandler {
@Autowired
private WordsService wordsService;
@RequestMapping("/findWords")
public ModelAndView findWords(Words words,HttpServletRequest request){
ModelAndView modelAndView=new ModelAndView();
List<Words> ws= wordsService.findWords(words);
modelAndView.addObject("ws",ws);
modelAndView.setViewName("forward:/page/message.jsp");
request.getSession().setAttribute("ws",ws);
if(words==null){
request.setAttribute(ServletUtil.ERROR_MESSAGE, "没有留言内容");
//return "redirect:/page/message.jsp";
}else{
//return "redirect:/page/lw-index.jsp";
}
System.out.println(ws);
return modelAndView;
}
映射文件
<resultMap type="Words" id="WordsMap">
<id column="wid" property="wid" />
<result column="waid" property="waid" />
<result column="wfrendid" property="wfrendid" />
<result column="wcontent" property="wcontent" />
<result column="waddress" property="waddress" />
<result column="wdate" property="wdate" />
<collection property="comments" ofType="Comments">
<id column="cid" property="cid" />
<result column="callid" property="callid" />
<result column="detail" property="detail" />
<result column="comuserid" property="comuserid" />
<result column="comTime" property="comTime" />
</collection>
<collection property="replys" ofType="Replys">
<id column="rid" property="rid" />
<result column="rcid" property="rcid" />
<result column="ruserid" property="ruserid" />
<result column="rtargetid" property="rtargetid" />
<result column="rcontent" property="rcontent" />
<result column="rtime" property="rtime" />
</collection>
</resultMap>
<select id="findWords" resultMap="WordsMap">
select w.*,c.*,r.*
from words w
inner join comments c
on w.wid=c.callid
inner join replys r
on c.cid=r.rcid
</select>
JSP页面
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:forEach var="k" items="${ws}">
<li >${k.wfrendid}</li>
<li >${k.wdate}</li>
<li>${k.waddress}</li>
<ul>
<c:forEach var="s" items="${k.comments}">
<li style="color:blue;">${s.comuserid}</li>
<li style="color:grey;">${s.comTime}</li>
<textarea style="width:500px">${s.detail}</textarea>
<a href="javascript:void(0)" οnclick="add();" style="color:red;">编辑</a>
<a href="javascript:void(0)" style="color:red;">发表</a>
</c:forEach>
</ul>
<br>
<label>显示您的回复</label>
<ul>
<c:forEach var="r" items="${k.replys}">
<li style="color:blue;">${r.ruserid}</li>
<li style="color:grey;">${r.rtime}</li>
</c:forEach>
</ul>
</c:forEach>
三个实体类 (需要序列化)
public class Words implements Serializable{//留言板
private static final long serialVersionUID = 3689509625432377305L;
private String wid;
private String waid;
private String wfrendid;
private String wcontent;
private String waddress;
private String wdate;
private List<Comments>comments;
private List<Replys> replys;
}