首先还是三层框架
配置文件
动态SQL 例如:
<select id="serchAdmin" parameterType="java.util.Map" resultType="Adminuser">
select * from adminuser
<where>
<if test="adminname != null">
and adminname like concat('%',#{adminname},'%')
</if>
<if test="roleid != null and roleid!= ''">
and roleid = #{roleid}
</if>
</where>
</select>
Controller 里的
@RequestMapping(value="admin/list")
public String list(Model model,String adminname,Integer roleid){
List<Roleinfo> roleList =adminService.getAllRole();
List<Adminuser> list =null;
//条件查询
String key = String.format("admin_%s_%s", adminname,roleid);
list = (List<Adminuser>) MemcachedUtil.get(key);
if(list != null){
System.out.println("从缓存中取数据");
}else{
System.out.println("从数据库中去数据!");
//list=adminService.getAllAdminuser();
list = adminService.serchAdmin(adminname,roleid);
MemcachedUtil.add(key, list, 20000);
}
model.addAttribute("list", list);
model.addAttribute("roleList", roleList);
model.addAttribute("adminname", adminname);
model.addAttribute("roleid", roleid);
return "admin/list";
}
存到缓存中的key不能写死,动态拼!
一定要注意!