日期:2014-05-19  浏览次数:20970 次

求指教 。
Dao层:
package com.shhelian.app.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.shhelian.app.model.Test;
import com.shhelian.modules.orm.hibernate.BaseDAO;

@Component("testDao")
public class TestDao extends BaseDAO<Test> {

public List find(String hql){
return this.getHibernateTemplate().find(hql);
}

}
Service层:
package com.shhelian.app.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.shhelian.app.dao.TestDao;


@Component("testService")
public class TestService {

private TestDao testDao;


public List find(){
return this.testDao.find("from Test");
}



public TestDao getTestDao() {
return testDao;
}
@Resource
public void setTestDao(TestDao testDao) {
this.testDao = testDao;
}





}
Action层:
package com.shhelian.app.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.shhelian.app.model.Test;
import com.shhelian.app.service.TestService;
import com.shhelian.modules.web.struts2.BaseCRUDAction;

@Component("test")
@Scope("prototype")
public class TestAction extends BaseCRUDAction<Test> {

private Test test;
private List testList;
private TestService testService;

@Override
protected void prepareModel() throws Exception {
System.out.println("xxxxxxxxxxxxxxxxx");
test = new Test();
}


public String show(){
testList = this.testService.find();
return SUCCESS;
}


@Override
public Test getModel() {
return test;
}


public Test getTest() {
return test;
}


public void setTest(Test test) {
this.test = test;
}


public List getTestList() {
return testList;
}


public void setTestList(List testList) {
this.testList = testList;
}


public TestService getTestService() {
return testService;
}

@Resource
public void setTestService(TestService testService) {
this.testService = testService;
}



}
index.jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<