我的Mysql表结构是这样的
id category name
这是jsp中的显示方式
<c:forEach items="${parentList}" var="test">
<ul style="max-width: 300px;" class="nav nav-pills nav-stacked">
<li class="active"><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);">
<input type="checkbox" value="${test.id}">${test.name }</a></li>
</ul>
</c:forEach>
parentList通过以下方法获取
List<Parent> parentList =
(List<Parent>) serviceClientServiceImpl.getParents("Parent",Long.valueOf(clientId));
这是我的serviceClientServiceImpl.getParents
public List<Parent> getParents(String entityName,Long clientId)
{
List<Parent> parentsList = null;
try
{
parentsList = (List<Parent>) serviceClientDaoImpl.getParents(entityName,clientId);
}
catch(Exception e)
{
}
return parentsList;
}
这是我的serviceClientDaoImpl.getParents
public List<Parent> getParents(String entityName,Long cId)
{
String queryString="";
queryString="select p FROM "+entityName+"p WHERE category=default or category=client and p.cid="+cId;
Query query=entityManagerUtil.getQuery(queryString);
query.setParameter("cId", cId);
return query.getResultList();
}
问题是我在 html 中没有看到任何内容。所以任何人都可以告诉我出了什么错误
最佳答案
尝试这样('' 中的 varchars):
从“+entityName+”p WHERE p.category='default' 或 p.category='client' 和 p.cid="+cId"中选择 p;
关于java - 如何从表中获取用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23843437/