ssh2中hql语句取数据表部分字段以及使用jquery easyui的datagrid的问题

J2EE 码拜 9年前 (2015-04-10) 1721次浏览 0个评论

我的实体类Course(就是班级课表的一条信息,里面有上课时间、地点之类的)是这个
public class Course implements java.io.Serializable {

private static final long serialVersionUID = 1L;
private Long courseId;
private Experiment experiment;
private ClassInfo classInfo;
private String experimentName;
private String className;
private Long studentId;
private String attendPlace;
private Timestamp attendTime;
private Timestamp endTime;
private Timestamp previewStartTime;
private Timestamp createTime;
private Timestamp modifyTime;
private Set previewInfos = new HashSet(0);

// Constructors

/** default constructor */
public Course(){}
public Course(String experimentName,String attendPlace,Timestamp attendTime,
 Timestamp endTime,Timestamp previewStartTime) {//这个构造方法是为了配合DAO里面的hql语句使用的。
this.experimentName = experimentName;
this.attendPlace = attendPlace;
this.attendTime = attendTime;
this.endTime = endTime;
this.previewStartTime = previewStartTime;
}
在CourseDAOImpl中调用的方法就是这个了
public class CourseDAOImpl extends BizPlatDAO<Course, Long> implements CourseDAO{

@Override
public List<Course> getCourseByClass(Long classId,int currentPage,int pageSize) {
String sql = “select new Course(experimentName,attendPlace,attendTime,endTime,previewStartTime)” +
” from Course”;//大神帮我看看这个写的对不对,我在实体类里面已经写了这个的构造方法了,还是报错,难道我写的不对?
Query query = this.getSession().createQuery(sql);
query.setMaxResults(pageSize);
query.setFirstResult((currentPage-1)*pageSize);
List<Course> courses =query.list();
if (courses == null || courses.size() <= 0)
return null;
return courses;
}
在action里面是这个:
public String getCourseList(){
currentPage = Integer.parseInt(page);
pageSize    = Integer.parseInt(rows);
        courses=courseService.getCourseList(2, currentPage, pageSize);//就是这老是过不去。。。
total=courseService.getCourseCount(2);
try {
String json = “{“total”:”+total+” , “rows”:”+objectMapper.writeValueAsString(courses)+”}”;//这个是为datagrid准备的,writeValueAsString这个方法可以直接把一个list变成json字符串吗?求指教。
    return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}
报的错是这些:
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: cn.edu.bjfu.phy.model.Course]
00:19:41.268 [http-8080-2] DEBUG org.hibernate.hql.ast.ErrorCounter –  Unable to locate appropriate constructor on class [cn.edu.bjfu.phy.model.Course]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: cn.edu.bjfu.phy.model.Course]
org.hibernate.hql.ast.DetailedSemanticException: Unable to locate appropriate constructor on class [cn.edu.bjfu.phy.model.Course]
因为前面的这个一直不通过,所以datagrid那就一直没有测试  急cry
在struts2配置文件里这么写的
<action name=”getCourseList” method=”getCourseList”
  class=”cn.edu.bjfu.phy.action.CourseAction”>
     <result type=”json”>
       <param name=”root”>json</param>  
     </result>
  </action>已经把struts-default改成json-default了,大神们,这样做可以传到前台吗?
前台是这样的
$(“”#t_user””).datagrid里面的url:””<s:property value=””contextPath””/>/admin/getCourseList.action””,这个是好用的,
列是这些:                                   columns:[[
{
field:””experimentName”” ,
title:””实验名称”” ,
width:100 ,
align:””center””,

},
{
field:””attendPlace”” ,
title:””上课地点”” ,
width:100 ,
},{
  field:””attendTime”” ,
  title:””开始时间”” ,
width:100 ,
sortable : true 
},{
field:””endTime”” , 
title:””结束时间”” ,
width:50 ,
},{
field:””previewStartTime”” ,
title:””预习开始时间”” ,
width:100 ,
}
]] ,
pagination: true , 
pageSize: 10 ,
pageList:[5,10,15,20,50] ,
因为娶不到数据嘛 页面显示出来是这个
ssh2中hql语句取数据表部分字段以及使用jquery easyui的datagrid的问题
可是底下这个面板的close是true啊,应该是只有点击新增的时候才会跳出来。。。会不会是jquery和easyui的js版本不匹配呢
求大神解答,感激不尽!

ssh2中hql语句取数据表部分字段以及使用jquery easyui的datagrid的问题
100分
虽然不知道你的 HQL 是干啥的,不知道 String sql = “from Course”; 行不行呢?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ssh2中hql语句取数据表部分字段以及使用jquery easyui的datagrid的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!