递归输出到Fremarkers

时间:2018-05-28 06:13:24

标签: html spring-boot recursion freemarker

我正在尝试从表中递归显示网站上的消息...现在,如截图所示,但在模板中,显示最多2个附件的硬核,告诉我如何编写正确的递归,以显示尽可能多的附件,而不是硬核。

example of how it works now

table

template.ftl

<#list comment as msg>
<#if !msg.reply??>
    <li>
        ${msg.message}
        <ul>
            <li>
        <#list replyes as reply>
            <#if reply.reply.toString() == msg.toString()>
                ${reply.message}
                <#list replyes as sub_reply>
                    <#if sub_reply.reply.toString() == reply.toString()>
                        <ul>
                            <li>
                                ${sub_reply.message}
                            </li>
                        </ul>
                    </#if>
                </#list>
            </#if>
          </#list>
            </li>
        </ul>
    </li>
  </#if>
</#list>

控制器:

@GetMapping(value = "chat")
public String charPage(@AuthenticationPrincipal User user,
                   Map<String, Object> model) {
model.put("comment",commentRepo.findAllByMessageIsNotNullOrderById());
model.put("replyes",commentRepo.findAllByReplyIsNotNull());

return "chatmessage";
}

回购:

public interface CommentRepo extends JpaRepository <Comment, Long> {
   List<Comment> findAllByMessageIsNotNullOrderById();
   List<Comment> findAllByReplyIsNotNull();
}

实体:

@Entity
public class Comment {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private String message;


@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "comment_id")
private Comment reply;


@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User user;


public Comment() {
}
.....

我试着写一个宏,但页面掉了。 宏:

<#list comment as msg>
<#if !msg.reply??>
    <li>
        ${msg.message}
        <ul>
            <li>
                <@treeView msg, replyes/>
            </li>
        </ul>
    </li>
</#if>
</#list>

<#macro treeView msg listReply>
  <#list listReply as reply>
    <#if reply.reply.toString() == msg.toString>
    ${reply.message}
    <@ treeView reply, replyes/>
    </#if>
  </#list>
</#macro>

告诉我如何在Freemarkers中编写正确的宏或方法

1 个答案:

答案 0 :(得分:0)

Here is a well-functioning macro for searching in the recursive records table.

import numpy as np
from numpy import linalg as npla
#
def eigen(A):
    eigenValues, eigenVectors = npla.eig(A)
    idx = np.argsort(eigenValues)
    eigenValues = eigenValues[idx]
    eigenVectors = eigenVectors[:,idx]
    return (eigenValues, eigenVectors)