我正在尝试制定一个示例 Spring Boot(MVC) 项目,我正在尝试以相同的顺序执行以下操作。
添加一位客户
添加具有客户 ID 的联系人
添加具有客户和联系人 ID 的 Oppr
向联系人发送电子邮件
添加具有 opprId 的票证
这里的主要问题是我试图在一笔交易下完成所有任务。但是添加票的方法在另一个类中。在尝试添加票时,我需要将 opprId 发送到 TicketAdd 类。当我不在方法级别使用@Transaction 时,我能够获取全局变量值,但目前我在 AddTicket 类中使用 @Transaction 来获取 addFields 方法,然后无法获取全局变量的值。
这是我的 OpprAdd 服务类。
package com.transaction.spring.service;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;
import com.transaction.spring.model.Customer;
import com.transaction.spring.model.CustomerContact;
import com.transaction.spring.model.SalesOppr;
import com.transaction.spring.repo.ContactRepo;
import com.transaction.spring.repo.CustomerRepo;
import com.transaction.spring.repo.OpprRepo;
@Service
public class OpprAdd {
@Autowired
ContactRepo contactRepo;
@Autowired
CustomerRepo customerRepo;
@Autowired
OpprRepo opprRepo;
@Autowired
TicketAdd ticketAdd;
public ModelAndView getModelAndView(Model model, ModelAndView modelAndView) {
modelAndView.addObject("SalesOppr", new SalesOppr());
modelAndView.setViewName("enquiry-add");
return modelAndView;
}
public ModelAndView postModelAndView(Model model, SalesOppr SalesOppr, ModelAndView modelAndView) {
addOppr(SalesOppr);
modelAndView.addObject("SalesOppr", SalesOppr);
modelAndView.setViewName("enquiry-add");
return modelAndView;
}
private void sendEmailSms(SalesOppr SalesOppr) {
System.err.println("123");
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addOppr(SalesOppr SalesOppr) {
Customer Customer = new Customer();
Customer.setCustomerName(SalesOppr.getCustomerName());
customerRepo.save(Customer);
}
}
12345678_0001
临摹微笑
相关分类