Java tutorial
package cn.com.jandar.lawyer.service; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.hibernate.Criteria; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import cn.com.jandar.lawyer.dao.LawyerDao; import cn.com.jandar.lawyer.model.Lawyer; /** * service * @author Chengw * @since 201731 ?4:30:13 * */ @Transactional @Service("lawyerService") public class LawyerService { @Resource LawyerDao lawyerDao; /** * ?id * @param id * @return */ public Lawyer findById(String id) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.eq("id", id)); return (Lawyer) c.uniqueResult(); } /** * ??? * @param licenseNumber * @return */ public Lawyer findByLicenseNumber(String licenseNumber) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.eq("licenseNumber", licenseNumber)); return (Lawyer) c.uniqueResult(); } /** * ??? * @param idNumber * @return */ public Lawyer findByIdNumber(String idNumber) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.eq("idNumber", idNumber)); return (Lawyer) c.uniqueResult(); } /** * ?id * @param personId * @return */ @SuppressWarnings("unchecked") public List<Lawyer> findByPersonId(String personId) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.eq("personId", personId)); return c.list(); } /** * ?id * @param practiceOrg * @return */ @SuppressWarnings("unchecked") public List<Lawyer> findByPracticeOrg(String practiceOrg) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.eq("practiceOrg", practiceOrg)); return c.list(); } /** * ?? * @param lastUpdateDate * @return */ @SuppressWarnings("unchecked") public List<Lawyer> findByLastUpdateDate(Date lastUpdateDate) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); c.add(Restrictions.ge("lastUpdateDate", lastUpdateDate)); return c.list(); } /** * ? * @param lastUpdateDate * @param pageNum * @param pageSize * @return */ @SuppressWarnings("unchecked") public List<Lawyer> findByParam(Date lastUpdateDate, Integer pageNum, Integer pageSize) { Criteria c = lawyerDao.getSession().createCriteria(Lawyer.class); if (lastUpdateDate != null) { c.add(Restrictions.ge("lastUpdateDate", lastUpdateDate)); } c.setMaxResults(pageSize); c.setFirstResult(pageNum * pageSize + 1); c.addOrder(Order.desc("laseUpdateDate")); return c.list(); } /** * ? * @param lawyers */ public void saveLawyerList(List<Lawyer> lawyers) { int n = 0; for (Lawyer lawyer : lawyers) { lawyerDao.getSession().saveOrUpdate(lawyer); if (n / 100 == 0) { lawyerDao.getSession().flush(); } } } }