使用 JPA 的 Spring MVC 应用程序
我的申请流程如下:
@Controller
Class
---> 返回 View (JSP) 页面。
在返回 View 之前,我想修改内容,或者在将其发送到实体持久服务层之前,希望更改一些值。我应该在哪里引入这些类?
编辑:
我清楚如何从数据库渲染数据并显示到前 View 。 我其实想问的是:
A a = aService.findXXX(aId);
//here i want some operations to be performed for specific view while converting it to dto and sending it to UI.
将引入执行相同操作的类,否则我的 Controller 将具有非常大的代码行 sp。必须向 sp 显示的内容。查看?
最佳答案
正如 @chrylis 所说,你在问什么不是很清楚。但如果我理解正确的话,这会对你有所帮助。
通常的模式是您的@Controller
有一个@Autowired
服务引用
@Autowired
private MyService myService;
并且@Service
有一个对DAO类的@Autowired
引用(用@Repository
注释)。 Service封装业务逻辑,DAO层负责与数据库交互。
在您的情况下,您将从 Controller 调用一些服务方法,服务将更改实体并将其传递给 DAO,然后 Controller 将必要的数据填充到用于渲染适当的 Model
查看。
关于java - 查看 Spring MVC 中的逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28718902/