JavaWeb项目开发案例精粹-第6章报价管理系统-04Service层
1.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.Customer; 5 /** 6 * 客户业务接口 7 */ 8 public interface CustomerService extends DAO<Customer> { 9 10 }
2.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.Order; 5 /** 6 * 订单业务接口 7 */ 8 public interface OrderService extends DAO<Order> { 9 10 }
3.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.Product; 5 /** 6 * 产品业务接口 7 */ 8 public interface ProductService extends DAO<Product> { 9 10 }
4.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.ProductType; 5 /** 6 * 产品类别业务接口 7 */ 8 public interface ProductTypeService extends DAO<ProductType> { 9 10 }
5.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.Quotation; 5 /** 6 * 报价业务接口 7 */ 8 public interface QuotationService extends DAO<Quotation> { 9 10 }
6.
1 package com.sanqing.service; 2 3 import com.sanqing.dao.DAO; 4 import com.sanqing.po.User; 5 6 /** 7 * 用户业务接口 8 */ 9 public interface UserService extends DAO<User> { 10 11 /** 12 * 判断用户是否存在 13 * @param username 用户名 14 * @param password 密码 15 * @return 16 */ 17 public boolean login(String username, String password) ; 18 }
7.
1 package com.sanqing.serviceImpl; 2 3 import org.springframework.stereotype.Service; 4 5 import com.sanqing.dao.DaoSupport; 6 import com.sanqing.po.Customer; 7 import com.sanqing.service.CustomerService; 8 9 @Service 10 public class CustomerServiceImpl extends DaoSupport<Customer> implements 11 CustomerService { 12 13 }
8.
1 package com.sanqing.serviceImpl; 2 import java.util.Date; 3 4 import org.springframework.stereotype.Service; 5 6 import com.sanqing.dao.DaoSupport; 7 import com.sanqing.po.Order; 8 import com.sanqing.service.OrderService; 9 10 @Service 11 public class OrderServiceImpl extends DaoSupport<Order> implements OrderService { 12 13 @Override 14 public void save(Object entity) { 15 Order order = (Order)entity; 16 order.setOrderTime(new Date()); 17 super.save(order); 18 } 19 20 @Override 21 public void update(Object entity) { 22 Order order = (Order)entity; 23 order.setOrderTime(new Date()); 24 super.update(entity); 25 } 26 }
9.
1 package com.sanqing.serviceImpl; 2 import org.springframework.stereotype.Service; 3 4 import com.sanqing.dao.DaoSupport; 5 import com.sanqing.po.Product; 6 import com.sanqing.service.ProductService; 7 8 @Service 9 public class ProductServiceImpl extends DaoSupport<Product> implements ProductService { 10 11 }
10.
1 package com.sanqing.serviceImpl; 2 3 import org.springframework.stereotype.Service; 4 5 import com.sanqing.dao.DaoSupport; 6 import com.sanqing.po.ProductType; 7 import com.sanqing.service.ProductTypeService; 8 9 @Service 10 public class ProductTypeServiceImpl extends DaoSupport<ProductType> implements 11 ProductTypeService { 12 }
11.
1 package com.sanqing.serviceImpl; 2 3 import java.util.Date; 4 5 import org.springframework.stereotype.Service; 6 7 import com.sanqing.dao.DaoSupport; 8 import com.sanqing.po.Quotation; 9 import com.sanqing.service.QuotationService; 10 11 @Service 12 public class QuotationServiceImpl extends DaoSupport<Quotation> implements 13 QuotationService { 14 15 @Override 16 public void save(Object entity) { 17 Quotation quotation = (Quotation)entity; 18 quotation.setQuotationTime(new Date()); 19 super.save(entity); 20 } 21 22 @Override 23 public void update(Object entity) { 24 Quotation quotation = (Quotation)entity; 25 quotation.setQuotationTime(new Date()); 26 super.update(entity); 27 } 28 29 }
12.
1 package com.sanqing.serviceImpl; 2 3 import org.springframework.stereotype.Service; 4 5 import com.sanqing.dao.DaoSupport; 6 import com.sanqing.po.User; 7 import com.sanqing.service.UserService; 8 9 @Service 10 public class UserServiceImpl extends DaoSupport<User> implements UserService { 11 12 public boolean login(String username, String password) { 13 long count = (Long)em.createQuery("select count(o) from User o where o.username=?1 and o.password=?2") 14 .setParameter(1, username).setParameter(2, password).getSingleResult(); 15 return count>0; 16 } 17 18 }
13.
You can do anything you set your mind to, man!