In my application I have a DTO that I use for the view of my new-delivery page. Do I send the data to my DeliveryService through my controller: (not sure if this is right)
@Controller public class DeliveryController { @Resource(name="deliveryService") private DeliveryService deliveryService; @RequestMapping(value="/initForm", method=RequestMethod.GET) public String getAdd(Model model){ DeliveryDto form = new DeliveryDto(); model.addAttribute("formData", form); return "----view----"; } @RequestMapping(value="/postForm", method=RequestMethod.POST) public String postAdd(@ModelAttribute("formData") DeliveryDto form, Model model) { deliveryService.createDelivery(form.getCustomerName(), form.getCustomerCountry()); return "----view----"; } }
Or do I retrieve that data in my DeliveryService?
The reason I am using a DTO is that I have some IDs in my Delivery table that I don't want the user to have to enter.
I use a customer Service+DTO to retrieve the ID corresponding to a pair of customerNames and customerCountries.
CustomerDAO:
@Repository public class CustomerDaoImpl implements CustomerDao { @Autowired(required=true) private SessionFactory sessionFactory; public Customer getCTID(String customerName, String customerCountry) { //Is it right to use a query here to get the Id? return (Customer) this.sessionFactory.getCurrentSession().createQuery( "select customerId from Customer where customerName = :name and customerCountry = :country") .setParameter("name", customerName).setParameter("country", customerCountry).uniqueResult(); } }
CustomerService:
@Service public class CustomerServiceImpl implements CustomerService { @Autowired(required=true) private CustomerDao customerDao; @Transactional public Customer retrieveCTID(String customerName, String customerCountry) { return this.customerDao.getCTID(customerName, customerCountry); } }
I don't know how I would write the DeliveryService/DAO so that it takes some DTO data and the data from CustomerService and persists it as a new delivery in the DeliveryTable.
Thank you for your help!
/D