三大框架中模糊查询代码
js获取查询条件,并去后台查询
function queryByName(){
//获取查询条件的用户名
var queryName=$("#queryName").val();
alert(queryName);
//进行后台跳转
window.location.href="<%=request.getContextPath() %>/master/sysUser_queryByName.action?queryName="+encodeURI(encodeURI(queryName));
}
action层
public String queryByName() throws UnsupportedEncodingException{
//进行解码
String name = java.net.URLDecoder.decode(queryName,"UTF-8");
this.list=sysUserService.querySysUserByName(name);
return "userList";
}
service层
@Override
public List<SysUser> querySysUserByName(String queryName) {
return sysUserDao.queryByQueryName(queryName);
}
dao层
public List<SysUser> queryByQueryName( final String queryName){
return super.getHibernateTemplate().executeFind(new HibernateCallback<List<SysUser>>() {
@Override
public List<SysUser> doInHibernate(Session session)
throws HibernateException, SQLException {
Query query=session.createSQLQuery("SELECT * FROM sys_user WHERE sys_user_name LIKE ?")
.addEntity(SysUser.class);
query.setParameter(0,"%"+queryName+"%");
return query.list();
}
});
}