package com.hp.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import com.hp.domain.Back;
import com.hp.domain.User;
public interface BackMapper {
//显示
public List<Back> findAll(Back back);
//查询
@Select("select * from tab_user")
public List<User> chaxun();
//删除
@Delete("delete from tab_feedback where id=#{id}")
public void del(Integer id);
//登录
@Select("select * from tab_user where uname=#{uname} and pwd=#{pwd}")
public User dl(User user);
//新增
@Insert("insert tab_feedback(author,commit_time,title,content,OPEN) values(#{author},#{commit_time},#{title},#{content},#{OPEN})")
public void add(Back back);
}
<mapper namespace="com.hp.dao.BackMapper">
<resultMap type="Back" id="backList"></resultMap>
<select id="findAll" resultMap="backList">
select tab_feedback.*,uname
from tab_user,tab_feedback
where tab_user.id=tab_feedback.author
<!-- and uname = #{uname} -->
<if test="title!=null and title!=''">
and title like CONCAT ('%',#{title},'%')
</if>
<if test="OPEN!=null">
and OPEN=#{OPEN}
</if>
</select>
</mapper>
package com.hp.controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hp.domain.Back;
import com.hp.domain.User;
import com.hp.service.BackService;
@Controller
public class BackController {
@Autowired
private BackService backService;
//显示
@RequestMapping("/findAll")
public ModelAndView findAll(Back back)
{
ModelAndView mv=new ModelAndView();
mv.addObject("backList", backService.findAll(back));
//调用组合查询
mv.addObject("zhcx", backService.chaxun());
mv.setViewName("index");
return mv;
}
//删除
@RequestMapping("/del/{id}")
public ModelAndView del(@PathVariable Integer id)
{
ModelAndView mv=new ModelAndView();
backService.del(id);
mv.setViewName("redirect:/findAll");
return mv;
}
//登录
@RequestMapping("/login")
public ModelAndView dl(User user,HttpSession session)
{
ModelAndView mv=new ModelAndView();
if(backService.dl(user)!=null)
{
//session.setAttribute("uname", user.getUname());
mv.setViewName("redirect:/findAll");
}
else
{
mv.setViewName("login");
}
return mv;
}
//新增页面
@RequestMapping("/xzym")
public ModelAndView xzym(HttpSession session)
{
ModelAndView mv=new ModelAndView();
/*mv.addObject("id", (Integer)session.getAttribute("id"));
mv.addObject("uname", (String)session.getAttribute("uname"));*/
backService.chaxun();
mv.setViewName("add");
return mv;
}
//新增
@RequestMapping("/add")
public ModelAndView add(Back back)
{
ModelAndView mv=new ModelAndView();
backService.add(back);
mv.setViewName("redirect:/findAll");
return mv;
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/findAll">
<p>
反馈标题<input type="text" name="title">
公开状态
<input type="radio" name="OPEN"value="0">不公开
<input type="radio" name="OPEN"value="1">公开
<input type="submit" value="查询">
<a href="${pageContext.request.contextPath}/xzym">发表反馈</a>
</p>
<table border="2px">
<tr>
<th>编号</th>
<th>反馈人</th>
<th>反馈时间</th>
<th>反馈标题</th>
<th>反馈内容</th>
<th>公开状态</th>
<th>操作</th>
</tr>
<c:forEach items="${backList}" var="b">
<tr>
<td>${b.id}</td>
<td>${b.uname}</td>
<td>${b.commit_time}</td>
<td>${b.title}</td>
<td>${b.content}</td>
<td>${b.OPEN==0?'不公开':(b.OPEN==1?'2':'4')}</td>
<td>
<a href="" οnclick="return confirm('确定要删除吗')">${b.OPEN==0?'':'不公开'}</a>
<a href="${pageContext.request.contextPath}/del/${b.id}" οnclick="return confirm('确定要删除吗')">删除</a>
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>