项目框架sprign mvc hibernate 注解 jsp
这个是hql写法
public List<RegMarpripInfo> getAllMarpripInfo(int offset, int length) { // List<RegMarpripInfo> entitylist = null; String hql = "select new Map( o.id as id ,o.entname as entname ,o.uniscid as uniscid, t.name as enttype, o.regno as regno , o.opscope as opscope, o.regcap as regcap ,i.name as industryco ,o.credit as credit, o.estdate as estdate ) from RegMarpripInfo o,CodeInd i,CodeEnttype t where 1=1 and o.enttype=t.code and o.industryco=i.code "; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setFirstResult(offset); query.setMaxResults(length); return query.list(); }
这个是sql写法的。 因为我不会注解方式左连接语句,就改成了sql写法
String sql = "select o.ID as id ,o.ENTNAME as entname ,o.UNISCID as uniscid, t.name as enttype, o.REGNO as regno , o.OPSCOPE as opscope, o.REGCAP as regcap ,i.name as industryco ,o.CREDIT as credit, o.ESTDATE as estdate from reg_marpripinfo o "
+ "LEFT JOIN code_indcode i on (i.NAME=o.INDUSTRYCO) "
+ "LEFT JOIN code_enttype t on (t.CODE=o.ENTTYPE) where 1=1 ";
Query query = sessionFactory.getCurrentSession().createSQLQuery(sql);
<th>注册号</th> <th>注册资本</th> <th>行业</th> <th>信用等级</th> </tr> <c:if test="${!empty marbb }"> <c:forEach items="${marbb }" var="mar"> <tr> <td>${mar.entname }</td> <td>${mar.uniscid }</td> <td>${mar.enttype }</td>
控制层代码
Page page = marManager.queryForPage(Integer.valueOf(pageNo), 10); request.setAttribute("page", page); List<RegMarpripInfo> mar = page.getList(); request.setAttribute("marList", mar);