@SuppressWarnings("unchecked")
@Path("getUsers.html")
@POST
@Produces({ MediaType.APPLICATION_JSON })
public Map getUserByName(MultivaluedMap<String, String> formParams) throws Exception {
String name=formParams.getFirst("name");
String project_id=formParams.getFirst("part_id");
List Users=null;
List<Part> parts=null;
users= jpaTemplate.find("select usp.user,usp.part.id as bid from USP usp where usp.user.name like '"+"%"+name+"%'");
parts= jpaTemplate.find("select usp.part from USP usp where usp.part.id='"+part_id+"'");
Map map=new HashMap();
map.put("users", users);
map.put("parts", parts);
return map;
}
<script type="text/javascript">
function cleanVal(){
document.getElementById('name').value="";
}
function setDefault(){
var value=document.getElementById('name').value;
if(value=="" || value==null){
document.getElementById('name').value="请输入姓名";
}
}
$(document).ready(function(){
$("#search").click(function(){
$.ajax({
url:"../../app/userManage/getUsers.html",
type:"POST",
data:$("#searchCondition").serialize(),
dataType:"json",
success:function(data){
try{
var html=' ';
$.each(data.users,function(i,item){
html += '<tr><td>'+ item[0].name +'</td><td>'+ item[0].sex+'</td><td>'+ item[0].addr +'</td>';
if(item[1]==" " || item[1] == null){
html += '<td>'+"未分配"+'</td></tr>';
}else{
$.each(data.parts,function(entryIndex,entry){
if(item[1]==entry.id){
html += '<td><a href="../userManage/to-user-detail.html?part_id='+entry.id+'&user_id=${user.id}" rel="external">'+entry.name+'</a></td></tr>';
return false;
}
});
$("#puser").html(html);
}catch(e){
alert("查询员工出现异常");
return;
}
},
error:function(result,status){
if(status == 'error'){
alert(status);
}
}
});
});
});
</script>
<form id="searchCondition" rel="external" data-ajax="false" enctype1="multipart/form-data">
<input name="part_id" type="hidden" value="${part.id}" />
<table width="90%" border="0" cellpadding="0" cellspacing="0"
style="margin: 4px">
<tr style="border: 0">
<td style="border: 0">
<label>搜索员工属于哪个部门:</label>
</td>
<td style="border: 0">
<input id="name" name="name" type="search" οnfοcus="cleanVal()" οnblur="setDefault()" value="请输入姓名" style="width: 100%" />
</td>
<td style="width: 1px; border: 0">
<input id="search" type="button" value="搜索" />
</td>
</tr>
</table>
</form>
<h3>员工属于哪个部门</h3>
<table id="title" >
<thead class="ui-bar-b">
<tr>
<th>姓名</th>
<th>性别</th>
<th>地址</th>
<th>所在部门</th>
</tr>
</thead>
<tbody id="puser">
</tbody>
</table>
@Path("getUsers.html")
@POST
@Produces({ MediaType.APPLICATION_JSON })
public Map getUserByName(MultivaluedMap<String, String> formParams) throws Exception {
String name=formParams.getFirst("name");
String project_id=formParams.getFirst("part_id");
List Users=null;
List<Part> parts=null;
users= jpaTemplate.find("select usp.user,usp.part.id as bid from USP usp where usp.user.name like '"+"%"+name+"%'");
parts= jpaTemplate.find("select usp.part from USP usp where usp.part.id='"+part_id+"'");
Map map=new HashMap();
map.put("users", users);
map.put("parts", parts);
return map;
}
<script type="text/javascript">
function cleanVal(){
document.getElementById('name').value="";
}
function setDefault(){
var value=document.getElementById('name').value;
if(value=="" || value==null){
document.getElementById('name').value="请输入姓名";
}
}
$(document).ready(function(){
$("#search").click(function(){
$.ajax({
url:"../../app/userManage/getUsers.html",
type:"POST",
data:$("#searchCondition").serialize(),
dataType:"json",
success:function(data){
try{
var html=' ';
$.each(data.users,function(i,item){
html += '<tr><td>'+ item[0].name +'</td><td>'+ item[0].sex+'</td><td>'+ item[0].addr +'</td>';
if(item[1]==" " || item[1] == null){
html += '<td>'+"未分配"+'</td></tr>';
}else{
$.each(data.parts,function(entryIndex,entry){
if(item[1]==entry.id){
html += '<td><a href="../userManage/to-user-detail.html?part_id='+entry.id+'&user_id=${user.id}" rel="external">'+entry.name+'</a></td></tr>';
return false;
}
});
}
return true;
$("#puser").html(html);
}catch(e){
alert("查询员工出现异常");
return;
}
},
error:function(result,status){
if(status == 'error'){
alert(status);
}
}
});
});
});
</script>
<form id="searchCondition" rel="external" data-ajax="false" enctype1="multipart/form-data">
<input name="part_id" type="hidden" value="${part.id}" />
<table width="90%" border="0" cellpadding="0" cellspacing="0"
style="margin: 4px">
<tr style="border: 0">
<td style="border: 0">
<label>搜索员工属于哪个部门:</label>
</td>
<td style="border: 0">
<input id="name" name="name" type="search" οnfοcus="cleanVal()" οnblur="setDefault()" value="请输入姓名" style="width: 100%" />
</td>
<td style="width: 1px; border: 0">
<input id="search" type="button" value="搜索" />
</td>
</tr>
</table>
</form>
<h3>员工属于哪个部门</h3>
<table id="title" >
<thead class="ui-bar-b">
<tr>
<th>姓名</th>
<th>性别</th>
<th>地址</th>
<th>所在部门</th>
</tr>
</thead>
<tbody id="puser">
</tbody>
</table>