`
y806839048
  • 浏览: 1120500 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

spring-data-jpa需要特别弥补的地方

阅读更多

使用spring-data-jpa需要特别弥补的地方,这点mapper处理比较好

 

//弥补jpa单实体的不足用不同的工厂类操作复杂sql,mapper这点比较好在处理了单实体查询直接不用daoimpl下,即使用

xml进行复杂查询也不需要daoimpl

 

 

jpa 复杂操作弥补:

 

public class TbPowerGroupBeanDaoImpl implements ITbPowerGroupBeanDao {

 

@Autowired

public ESteelSqlSessionTemplate sqlSessionTemplate;

 

@Override

public List<Map<String,Object>> getBigPowerMenu(Map<String, Object> param) {

// TODO Auto-generated method stub

return sqlSessionTemplate.selectList("account.getBigPowerMenu", param);

}

}

 

 

public class UserBListDaoImpl implements UserBListDaoHelper{

 

@PersistenceContext

private EntityManager em;

 

@Override

public List<CusFirmBean> findCustomerExceptOne(Map<String, Object> paraMap) {

StringBuffer sb = new StringBuffer();

sb.append(" select distinct t.CUSTOMER_ID,t.CUSTOMER_KEY,t.CUSTOMER_NAME ");

sb.append(" from tb_user_blist t1 left join tb_cus_firm t on(t1.blist_customer_key=t.customer_key) ");

sb.append("  left join TB_USER_BLIST_LABEL t2 on(t1.blist_id=t2.blist_id) left join TB_USER_LABEL t3 on(t2.label_id=t3.label_id) ");

sb.append("  where t1.CUSTOMER_KEY=:CUSTOMER_KEY ");

if (!StringUtils.isNullObj(paraMap.get("CUSTOMER_NAME"))) {

sb.append(" and t.CUSTOMER_NAME like '%'||:CUSTOMER_NAME||'%'");

}

if (!StringUtils.isNullObj(paraMap.get("CUSTOMER_SEARCHKEY"))) {

sb.append(" and t.CUSTOMER_ID = :CUSTOMER_SEARCHKEY ");

}

if (!StringUtils.isNullObj(paraMap.get("label_name"))) {

sb.append(" and t3.label_name =:LABEL_NAME ");

}

if (!StringUtils.isNullObj(paraMap.get("selectedCustomerKey"))

&&paraMap.get("selectedCustomerKey").toString()!="[]") {

sb.append(" and t.CUSTOMER_KEY not in (:selectedCustomerKey)");

}

sb.append(" and t.CUS_TRADE_KIND = 'A'");

 

Query query = em.createNativeQuery(sb.toString());

query.setParameter("CUSTOMER_KEY", paraMap.get("CUSTOMER_KEY"));

if (!StringUtils.isNullObj(paraMap.get("CUSTOMER_NAME"))) {

query.setParameter("CUSTOMER_NAME", paraMap.get("CUSTOMER_NAME"));

}

if (!StringUtils.isNullObj(paraMap.get("CUSTOMER_SEARCHKEY"))) {

query.setParameter("CUSTOMER_SEARCHKEY", ((String) paraMap.get("CUSTOMER_SEARCHKEY")).toUpperCase());

}

if (!StringUtils.isNullObj(paraMap.get("label_name"))) {

query.setParameter("LABEL_NAME", paraMap.get("label_name"));

}

if (!StringUtils.isNullObj(paraMap.get("selectedCustomerKey"))

&&paraMap.get("selectedCustomerKey").toString()!="[]") {

query.setParameter("selectedCustomerKey", paraMap.get("selectedCustomerKey"));

}

List<Object[]> list = query.getResultList();

List<CusFirmBean> rstList = new ArrayList<CusFirmBean> ();

if(list!=null && list.size()>0) {

for(Object[] obj : list) {

CusFirmBean cus = new CusFirmBean ();

cus.setCustomerId(obj[0]!=null?obj[0].toString():"");

cus.setCustomerKey(NumberUtils.toLong(obj[1].toString()));

cus.setCustomerName(obj[2].toString());

rstList.add(cus);

}

}

return rstList;

}

}

 

 

 

jpa dao层直接操作(只限于单实体):

 

 

 

@Component("basLkpService")

public class BasLkpServiceImpl implements BasLkpService {

 

    @Autowired

    public BasAreaDao basAreaDao;

    

    @Autowired

    public BasLkpDao basLkpDao;

    

    @Override

    public List<BasAreaBean> getAllProvince() {

        

        return basAreaDao.findByAreaLevel("1");

    

    }

 @Override

public BasLkpBean getTbBasLkpByBusinessTypeLookupType(String businessType, String priceType) {

BasLkpBeanPK pk=new BasLkpBeanPK();

pk.setBusinessType(businessType);

pk.setLookupType(priceType);

return basLkpDao.findOne(pk);

}

}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics