这是sql写法
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写法的
public List<RegMarpripInfo> getAllMarpripInfo(int offset, int length) {
// List<RegMarpripInfo> entitylist = null;
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);
query.setFirstResult(offset);
query.setMaxResults(length);
return query.list();
}
因为不太了解注解写hql左连接就转成了sql写法,但是sql写法一直报错for input string,
要展示的列全部报这个错,
严重: Servlet.service() for servlet springMVC threw exception
java.lang.NumberFormatException: For input string: "entname"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:160)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
项目框架spring mvc hibernate注解 jsp
控制层代码
Page page = marManager.queryForPage(Integer.valueOf(pageNo), 10);
request.setAttribute("page", page);
List<RegMarpripInfo> mar = page.getList();
request.setAttribute("marList", mar);