java 프로젝트의 공공 인터페이스GenericDao와GenericService
4943 단어 사업 총결산
package com.yufei.core.generic;
import java.util.List;
import org.apache.ibatis.annotations.Select;
/**
* Dao , ,
* Mybatis Generator Maven Dao,
* , GenericDao .
*
* Model : Java
* PK :
*
* @author StarZou
* @since 2014 6 9 6:14:06
*/
public interface GenericDao {
/**
*
*
* @param model
*/
int insertSelective(Model model);
/**
*
*
* @param model
*/
int updateByPrimaryKeySelective(Model model);
/**
*
*
* @param model
*/
int updateByPrimaryKey(Model model);
/**
* ,
*
* @param id
*/
int deleteByPrimaryKey(PK id);
/**
* ,
*
* @param id
* @return
*/
Model selectByPrimaryKey(PK id);
/**
*
* @return
*/
List selectByExample();
/**
*
* @return
*/
@Select("SELECT @@IDENTITY")
long getLastInsertID();
}
GenericService
package com.yufei.core.generic;
import java.util.List;
/**
* Service ,
*
* Model : Java
* PK :
*
* @author StarZou
* @since 2014 6 9 6:14:06
*/
public interface GenericService {
/**
*
*
* @param model
*/
int insertSelective(Model model);
/**
*
*
* @param model
*/
int updateSelective(Model model);
/**
* ,
*
* @param id
*/
int delete(PK id);
/**
* ,
*
* @param id
* @return model
*/
Model selectById(PK id);
/**
*
*
* @return
*/
Model selectOne();
/**
*
*
* @return
*/
List selectAllList();
/**
* (Mysql)
* @return
*/
long getLastInsertID();
}
GenericServiceImpl
package com.yufei.core.generic;
import java.util.List;
import com.yufei.core.util.DateUtil;
import com.yufei.core.util.PageData;
import com.yufei.core.util.ReflectUtil;
import com.yufei.erp.basis.model.my.MySysDeptPerson;
/**
* GenericService , ServiceImpl, , ,
*
*
* Model : Java
* PK :
*
* @author StarZou
* @since 2014 6 9 6:14:06
*/
public abstract class GenericServiceImpl implements GenericService {
/**
* , , dao
*
* @return GenericDao
*/
public abstract GenericDao getDao();
/**
*
*
* @param model
*/
public int insertSelective(Model model) {
return getDao().insertSelective(model);
}
/**
*
*
* @param model
*/
public int updateSelective(Model model) {
return getDao().updateByPrimaryKeySelective(model);
}
/**
*
*
* @param model
*/
public int update(Model model) {
return getDao().updateByPrimaryKey(model);
}
/**
* ,
*
* @param id
*/
public int delete(PK id) {
return getDao().deleteByPrimaryKey(id);
}
/**
* ,
*
* @param id
* @return
*/
public Model selectById(PK id) {
return getDao().selectByPrimaryKey(id);
}
@Override
public Model selectOne() {
return null;
}
@Override
public List selectAllList() {
return getDao().selectByExample();
}
@Override
public long getLastInsertID() {
return getDao().getLastInsertID();
}
/**
* 【 】
* @param model
* @param paramMap
*/
public void setRecordCreateInfo(Object model, PageData pd) {
//
MySysDeptPerson userinfo = (MySysDeptPerson) pd.getSession("userInfo");
// model
ReflectUtil.setModelValue(model, "createdate", DateUtil.getTime()); //
ReflectUtil.setModelValue(model, "createuser", userinfo.getUsername()); //
}
/**
* 【 】
* @param model
* @param paramMap
*/
public void setRecordModifyInfo(Object model, PageData pd) {
//
MySysDeptPerson userinfo = (MySysDeptPerson) pd.getSession("userInfo");
// model
ReflectUtil.setModelValue(model, "modifyuser", userinfo.getUsername()); //
ReflectUtil.setModelValue(model, "modifydate", DateUtil.getTime()); //
}
}
인스턴스 사용:
@Service public class RoleServiceImpl extends GenericServiceImpl implements RoleService
public interface SysRoleMapper extends GenericDao