<resultMap type="Back" id="backList"/>
<select id="findAll" resultMap="backList">
select * from tab_user,tab_feedback where tab_user.id=tab_feedback.author
<!-- 表示获取登录人的信息 -->
<if test="uname!=null and uname!=''">
and uname = #{uname}
</if>
<if test="title!=null and title!=''"> and title like CONCAT ('%',#{title},'%') </if>
</select>
</mapper>
//方法
//登录
@Select("select * from tab_user where uname=#{uname} and pwd=#{pwd}")
public User dl(User user);
//显示
public List<Back> findAll(Back back);
@Select("select id from tab_user where uname=#{uname}")
public Integer id(String uname);
//查询
@Select("select * from tab_user")
public List<User> chaxun();
//删除
@Delete("delete from tab_feedback where id=#{id}")
public void del(Integer id);
//新增
@Insert("insert tab_feedback(author,commit_time,title,content,OPEN values(#{author},#{commit_time},#{title},#{content},#{OPEN))")
public void add(Back back);
时间转换@DateTimeFormat(pattern="yyyy-MM-dd")
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>主页面
//登录
@RequestMapping("/login")
public ModelAndView dl(User user,HttpSession session)
{
ModelAndView mv=new ModelAndView();
if(backService.dl(user)!=null)
{
//保存用户名的信息
session.setAttribute("id", backService.id(user.getUname()));
session.setAttribute("uname", user.getUname());
mv.setViewName("redirect:/findAll");
}
else
{
mv.setViewName("login");
}
return mv;
}
//显示
@RequestMapping("/findAll")
public ModelAndView findAll(Back back,HttpSession session)
{
ModelAndView mv=new ModelAndView();
back.setUname((String)session.getAttribute("uname"));
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("/xzym")
public ModelAndView xzym(HttpSession session)
{
ModelAndView mv=new ModelAndView();
mv.addObject("id", (Integer)session.getAttribute("id"));
mv.addObject("uname", (String)session.getAttribute("uname"));
mv.setViewName("add");
return mv;
}
//新增
@RequestMapping("/add")
public ModelAndView add(Back back)
{
ModelAndView mv=new ModelAndView();
mv.setViewName("redirect:/findAll");
return mv;
}