您好我正在尝试创建用户登录,其中用户输入其用户名和密码,然后我的REST服务检索用户名和密码以检查它是否匹配。虽然这通过使用通过employeeId作为参数发送的GET请求,但我知道它已经工作了,但这意味着我必须在我的Android应用程序中对employeeId进行硬编码。
我正在尝试对getRecords()进行POST,它已将所有用户及其详细信息返回到ArrayList中。
这是我的REST服务中的getRecords()方法:
@Override
public List<UsersTable> getSpecificRecords(UserTableCriteria entity) {
boolean criteriaSet = false;
int firstResult = 0;
List<UsersTable> entityReturned;
// check if web side sent in any record retrieval instructions and use
// them instead
if (entity.getFirstResult() != null) {
firstResult = entity.getFirstResult();
}
// if maximum results to be returned sent by web application
// is less than normall allowed use that value
if (entity.getMaxResults() != null && entity.getMaxResults() < ApplicationConstants.MAX_RETURNED_RESULTS) {
maxResults = entity.getMaxResults();
} else {
maxResults = ApplicationConstants.MAX_RETURNED_RESULTS;
}
if (!session.isOpen()) {
this.session = HibernateUtil.getApplicationSessionFactory().getCurrentSession();
}
Transaction tx = session.beginTransaction();
session.clear();
Criteria criteria = session.createCriteria(UsersTable.class);
if (!StringUtils.isEmpty(entity.getUserName())) {
if (entity.getUserName().contains("*")) {
criteria.add(Restrictions.ilike("userName", entity.getUserName().replace('*', '%')));
} else {
criteria.add(Restrictions.eq("userName", entity.getUserName()).ignoreCase());
}
criteriaSet = true;
}
// set the sort order of the returned records
criteria.addOrder(Order.desc("userName"));
criteria.setMaxResults(maxResults);
criteria.setFirstResult(firstResult);
// validate there is at least one value to search on and run the query
if (criteriaSet) {
entityReturned = criteria.list();
session.close();
return entityReturned;
}
session.close();
return new ArrayList<>();
}
编辑:控制器代码
@POST
@Secured
@Path("/")
@Produces("application/xml, application/json")
@Consumes(MediaType.APPLICATION_JSON)
public Response getSpecificRecords(@HeaderParam("securityToken") String token, UserTableCriteria entity) {
// retrieve a list of entities based on specific criteria
UsersTableList entityList;
try {
entityList = usersTableBO.getSpecificRecords(entity);
LOGGER.debug("Successful single key table get specific was processed");
} catch (NotFoundException ex) {
LOGGER.debug(MessageFormat.format("Single key table get Specific failed because of error: {0}", ex.getMessage()));
return returnEntityResponse(Response.Status.NO_CONTENT);
}
return returnEntityResponse(entityList, Response.Status.OK);
}
我如何实现我想要做的事情?