小编Ram*_*ngh的帖子

为 Spring JPA 存储库方法配置切入点

我正在尝试创建一个在每次调用 Spring JpaRepository 的 save() 之后运行的方面。我将我的方面定义如下:

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ProcessAspect {

    @Autowired
    private ProcessService processService;

    @AfterReturning(value = "execution(* com.domain.control.repository.ProcessDao.save())))",
    returning = "result")
    private void propagateProcess(JoinPoint joinPoint, Object result) {
        log.info("Aspect is working, congratulations. Jointpoint {} , result {}", joinPoint, result.toString());
        Process process = (process) result;

       // do something on the object returned by save()
        processService.createOrUpdateProcess(process);
    }

}
Run Code Online (Sandbox Code Playgroud)

我的存储库定义如下:

@Repository
public interface ProcessDao extends JpaRepository<Process, String>
Run Code Online (Sandbox Code Playgroud)

如果我以这种方式配置它,那么该方面将无法正常工作。

如何配置我的方面以在通用 JPA …

java spring spring-aop

5
推荐指数
1
解决办法
7247
查看次数

使用 Ruby 中的 ActionMailer 类在电子邮件正文中呈现 HTML 字符串

我正在尝试使用 ActionMailer 类在 ROR 中发送邮件。

我创建了一个邮件对象,如:

mail(to: 'xyz@gmail.com', subject: "some subject text", body: template)
Run Code Online (Sandbox Code Playgroud)

这里的模板是一个字符串,其中包含要在邮件正文中呈现的 HTML。

当我尝试上述声明时,HTML 字符串会像在 Gmail 或任何其他客户端中一样显示,而不是被呈现。

我知道我可以为视图创建一个单独的 ERB 文件,邮件视图位于 app/views/name_of_mailer_class 目录中。

但我想渲染我从另一个源内联生成的 HTML 字符串,而不将其存储在文件中。

我也尝试过在下面的链接中找到的这种方法,但它产生了相同的结果。http://carols10cents.github.io/versioned_rails_guides/v3.2.2/action_mailer_basics.html

mail(:to => user.email,
         :subject => "Welcome to My Awesome Site") do |format|
      format.html { render 'another_template' }
      format.text { render :text => 'Render text' }
    end 
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails render actionmailer

2
推荐指数
1
解决办法
3147
查看次数

标签 统计

actionmailer ×1

java ×1

render ×1

ruby ×1

ruby-on-rails ×1

spring ×1

spring-aop ×1