【 tulaoshi.com - Web开发 】
dao层接口:
Java代码
代码如下:
package com.last999.im.news.dao;
import java.util.*;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
public interface KindEntityDao{
public KindEntity get(String uuid);
public void save(KindEntity kindEntity);
public void update(KindEntity kindEntity);
public void delete(String uuid);
public void delete(KindEntity kindEntity);
public ListKindEntity findAll();
public KindEntity findKindEntityByName(String name);
public ListKindEntity getKindEntity(PageTool pageInfo);
public int getRows();
}
代码如下:
package com.last999.im.news.dao;
import java.util.*;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
public interface KindEntityDao{
public KindEntity get(String uuid);
public void save(KindEntity kindEntity);
public void update(KindEntity kindEntity);
public void delete(String uuid);
public void delete(KindEntity kindEntity);
public ListKindEntity findAll();
public KindEntity findKindEntityByName(String name);
public ListKindEntity getKindEntity(PageTool pageInfo);
public int getRows();
}
package com.last999.im.news.dao.impl;
import java.util.*;
import com.last999.im.news.dao.KindEntityDao;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.web.PageTool;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class KindEntityDaoHibernate extends HibernateDaoSupport implements KindEntityDao{
public KindEntity get(String uuid){
return (KindEntity)getHibernateTemplate().get(KindEntity.class,uuid);
}
public void save(KindEntity kindEntity){
getHibernateTemplate().save(kindEntity);
}
public void update(KindEntity kindEntity){
getHibernateTemplate().saveOrUpdate(kindEntity);
}
public void delete(KindEntity kindEntity){
getHibernateTemplate().delete(kindEntity);
}
public void delete(String uuid){
getHibernateTemplate().delete((KindEntity)getHibernateTemplate().get(KindEntity.class,uuid));
}
public List findAll(){
return getHibernateTemplate().find("from KindEntity");
}
public KindEntity findKindEntityByName(String name){
List k1 = getHibernateTemplate().find("from KindEntity as ke where ke.name = ?",name);
if (k1 != null && k1.size() == 1){
return (KindEntity)k1.get(0);
}
return null;
}
public int getRows(){
return getHibernateTemplate().find("from KindEntity").size();
}
public List getKindEntity(PageTool pageInfo){
final int size1=pageInfo.getSize();
final int startRow=(pageInfo.getCur()-1)*pageInfo.getSize();
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public List doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery("from KindEntity");
query.setFirstResult(startRow);
query.setMaxResults(size1);
return query.list();
}
}
);
}
}
SERVICE层接口:
Java代码
代码如下:
package com.last999.im.news.service;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
public interface KindEntityManage{
public void addKindEntity(KindEntity entity);
public List findAllKind();
public int getRows();
public List getKindEntity(PageTool pageInfo);
}
代码如下:
package com.last999.im.news.service;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
public interface KindEntityManage{
public void addKindEntity(KindEntity entity);
public List findAllKind();
public int getRows();
public List getKindEntity(PageTool pageInfo);
}
实现类:
Java代码
代码如下:
package com.last999.im.news.service.impl;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
import com.last999.im.news.dao.KindEntityDao;
public class KindEntityManageImpl implements KindEntityManage{
private KindEntityDao kindEntityDao;
public KindEntityDao getKindEntityDao(){
return this.kindEntityDao;
}
public void setKindEntityDao(KindEntityDao kindEntityDao) {
this.kindEntityDao=kindEntityDao;
}
public void addKindEntity(KindEntity kindEntity){
this.getKindEntityDao().save(kindEntity);
}
public List findAllKind(){
return this.getKindEntityDao().findAll();
}
public int getRows(){
return this.getKindEntityDao().getRows();
}
public List getKindEntity(PageTool pageInfo){
return this.getKindEntityDao().getKindEntity(pageInfo);
}
}
代码如下:
package com.last999.im.news.service.impl;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
import com.last999.im.news.dao.KindEntityDao;
public class KindEntityManageImpl implements KindEntityManage{
private KindEntityDao kindEntityDao;
public KindEntityDao getKindEntityDao(){
return this.kindEntityDao;
}
public void setKindEntityDao(KindEntityDao kindEntityDao) {
this.kindEntityDao=kindEntityDao;
}
public void addKindEntity(KindEntity kindEntity){
this.getKindEntityDao().save(kindEntity);
}
public List findAllKind(){
return this.getKindEntityDao().findAll();
}
public int getRows(){
return this.getKindEntityDao().getRows();
}
public List getKindEntity(PageTool pageInfo){
return this.getKindEntityDao().getKindEntity(pageInfo);
}
}
action类:
Java代码
代码如下:
package com.last999.im.news.action;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.web.PageMaker;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
public class KindViewAction extends SafeStruts2{
private List kindList;
private KindEntity kindEntity;
private KindEntityManage kindEntityManage;
private int ppp;
private PageMaker pageMaker;
private String pager;
public String getPager(){
return this.pager;
}
public void setPager(String pager) {
this.pager=pager;
}
public PageMaker getPageMaker(){
return this.pageMaker;
}
public void setPageMaker(PageMaker pageMaker) {
this.pageMaker=pageMaker;
}
public int getPpp(){
return this.ppp;
}
public void setPpp(int ppp) {
this.ppp=ppp;
}
public KindEntityManage getKindEntityManage(){
return this.kindEntityManage;
}
public void setKindEntityManage(KindEntityManage kindEntityManage) {
this.kindEntityManage=kindEntityManage;
}
public KindEntity getKindEntity(){
return this.kindEntity;
}
public void setKindEntity(KindEntity kindEntity) {
this.kindEntity=kindEntity;
}
public List getKindList(){
return this.kindList;
}
public void setKindList(List kindList) {
this.kindList=kindList;
}
public String kindView(){
PageTool pageInfo = new PageTool();
pageInfo.setCur(this.getPpp());
pageInfo.setTotal(this.getKindEntityManage().getRows());
setKindList(this.getKindEntityManage().getKindEntity(pageInfo));
PageMaker pageMaker = new PageMaker();
setPager(pageMaker.makeList(pageInfo,"kindView.action?ppp="));
return SUCCESS;
}
}
代码如下:
package com.last999.im.news.action;
import java.util.List;
import com.last999.im.news.web.PageTool;
import com.last999.im.news.web.PageMaker;
import com.last999.im.news.entity.KindEntity;
import com.last999.im.news.service.KindEntityManage;
public class KindViewAction extends SafeStruts2{
private List kindList;
private KindEntity kindEntity;
private KindEntityManage kindEntityManage;
private int ppp;
private PageMaker pageMaker;
private String pager;
public String getPager(){
return this.pager;
}
public void setPager(String pager) {
this.pager=pager;
}
public PageMaker getPageMaker(){
return this.pageMaker;
}
public void setPageMaker(PageMaker pageMaker) {
this.pageMaker=pageMaker;
}
public int getPpp(){
return this.ppp;
}
public void setPpp(int ppp) {
this.ppp=ppp;
}
public KindEntityManage getKindEntityManage(){
return this.kindEntityManage;
}
public void setKindEntityManage(KindEntityManage kindEntityManage) {
this.kindEntityManage=kindEntityManage;
}
public KindEntity getKindEntity(){
return this.kindEntity;
}
public void setKindEntity(KindEntity kindEntity) {
this.kindEntity=kindEntity;
}
public List getKindList(){
return this.kindList;
}
public void setKindList(List kindList) {
this.kindList=kindList;
}
public String kindView(){
PageTool pageInfo = new PageTool();
pageInfo.setCur(this.getPpp());
pageInfo.setTotal(this.getKindEntityManage().getRows());
setKindList(this.getKindEntityManage().getKindEntity(pageInfo));
PageMaker pageMaker = new PageMaker();
setPager(pageMaker.makeList(pageInfo,"kindView.action?ppp="));
return SUCCESS;
}
}
分页辅助工具类:
Java代码
package com.last999.im.news.web;
public class PageTool{
private int cur=1;
private int size=6;
private int total=1;
public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}
public PageTool(){}
public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}
public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}
package com.last999.im.news.web;
public class PageTool{
private int cur=1;
private int size=6;
private int total=1;
public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}
public PageTool(){}
public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}
public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}
package com.last999.im.news.web;
public class PageTool{
private int cur=1;
private int size=6;
private int total=1;
public int getCur(){
return this.cur;
}
public void setCur(int cur) {
this.cur=cur;
}
public int getSize(){
return this.size;
}
public void setSize(int size) {
this.size=size;
}
public int getTotal(){
return this.total;
}
public void setTotal(int total) {
this.total=total;
}
public PageTool(){}
public PageTool(int cur,int size,int total){
this.cur=cur;
this.size=size;
this.total=total;
}
public PageTool(int size){
this.size=size;
this.cur=1;
this.total=1;
}
}