src/com/dream/service/impl/CustomerServiceImpl.java

(完整代码) 1KB

package com.dream.service.impl;


import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dream.bean.Customer;
import com.dream.dao.DaoSupport;
import com.dream.service.CustomerService;

@Service
@Transactional
public class CustomerServiceImpl extends DaoSupport implements CustomerService {

	
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public boolean isexits(String name){
		Query query = em.createQuery("select count(o) from Customer o where o.name=?1");
		query.setParameter(1, name);
		Long count = (Long)query.getSingleResult();
		if(count>=1){
			return true;
		}
		return false;
	}
	

	
	public void deleteCustomer(Long[] ids){
		 if(ids!=null&&ids.length>0){
			 StringBuffer jpql = new StringBuffer();
			 for(int i=0;i<ids.length;i++){
				 jpql.append("?").append(i+1).append(",");
			 }
			 jpql.deleteCharAt(jpql.length()-1);
			Query query = em.createQuery("delete from Customer o where o.id in("+jpql.toString()+")");
			for(int i=0;i<ids.length;i++){
				 query.setParameter(i+1, ids[i]);
			 }
			query.executeUpdate();
		 }
	}
	
	@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
	public Customer findByName(String name){
		Query query = em.createQuery("select o from Customer o where o.name=?1");
		query.setParameter(1, name);
		return (Customer)query.getSingleResult();
	}
	
	
	
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。