码迷,mamicode.com
首页 > 编程语言 > 详细

Java高级架构师(一)第12节:Service的实现以及模块化

时间:2018-12-12 20:32:43      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:service   架构   inter   void   接下来   str   model   comm   get   

BaseService.java

package com.sishuok.architecture1.common.service;

import java.util.List;

import com.sishuok.architecture1.common.dao.BaseDAO;
import com.sishuok.architecture1.common.vo.BaseModel;
import com.sishuok.pageutil.Page;


public class BaseService<M, QM extends BaseModel> implements IBaseService<M,QM> {
	private BaseDAO dao = null;
	public void setDAO(BaseDAO dao){
		this.dao = dao;
	}
	public void create(M m) {
		dao.create(m);
	}

	public void update(M m) {
		dao.update(m);
	}

	public void delete(int uuid) {
		dao.delete(uuid);
	}

	public M getByUuid(int uuid) {
		return (M)dao.getByUuid(uuid);
	}

	public Page<M> getByConditionPage(QM qm) {
		List<M> list = dao.getByConditionPage(qm);
		qm.getPage().setResult(list);
		
		return qm.getPage();
	}
}

 IBaseService.java

package com.sishuok.architecture1.common.service;

import com.sishuok.architecture1.common.vo.BaseModel;
import com.sishuok.pageutil.Page;


public interface IBaseService<M,QM extends BaseModel> {
	public void create(M m);
	public void update(M m);
	public void delete(int uuid);
	
	public M getByUuid(int uuid);
	public Page<M> getByConditionPage(QM qm);
}

在custom模块中,ICustomerService接口:

package com.sishuok.architecture1.customermgr.service;

import com.sishuok.architecture1.common.service.IBaseService;
import com.sishuok.architecture1.customermgr.vo.CustomerModel;
import com.sishuok.architecture1.customermgr.vo.CustomerQueryModel;

public interface ICustomerService extends IBaseService<CustomerModel, CustomerQueryModel>{
	public CustomerModel getByCustomerId(String customerId);
}

  接下来实现:

package com.sishuok.architecture1.customermgr.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sishuok.architecture1.common.service.BaseService;
import com.sishuok.architecture1.customermgr.dao.CustomerDAO;
import com.sishuok.architecture1.customermgr.vo.CustomerModel;
import com.sishuok.architecture1.customermgr.vo.CustomerQueryModel;

@Service
@Transactional
public class CustomerService extends BaseService<CustomerModel, CustomerQueryModel> implements ICustomerService{
	private CustomerDAO dao = null;
	@Autowired
	private void setDao(CustomerDAO dao){
		this.dao = dao;
		super.setDAO(dao);
	}
	public CustomerModel getByCustomerId(String customerId) {
		return dao.getByCustomerId(customerId);
	}
	
}

  

Java高级架构师(一)第12节:Service的实现以及模块化

标签:service   架构   inter   void   接下来   str   model   comm   get   

原文地址:https://www.cnblogs.com/sunrunzhi/p/10110560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!