如何使用百里香叶将动态数据从一个页面转换到另一个页面?

时间:2021-10-29 19:38:57

I want to get the information(which is dynamically generated) from one html page into another html page.

我想从一个html页面获取信息(动态生成)到另一个html页面。

I used a tag th:fragment in first html page and th:include in second html page.

我在第一个html页面中使用了标签th:fragment,并且在第二个html页面中使用了包含:

But i am getting only static content of first page, it is possible to get the dynamic data or not?can anyone help me please.

但我只获取第一页的静态内容,是否可以获取动态数据?任何人都可以帮助我。

Thanks in advance.

提前致谢。


@RequestMapping("/Menubar")
public String Ajax(Model model, HttpServletRequest req) {
    List l2 = new ArrayList();

    List l = menuService.listMenus();
    Iterator i = l.iterator();
    while (i.hasNext()) {
        String s = (String) i.next();
        System.out.println(s);

        List submenu = menuService.getSubMenu(s);

        System.out.println(submenu
                + "sub menuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu");

        menu m = new menu();
        m.setS(s);
        m.setL(submenu);
        l2.add(m);

    }
    HttpSession hs = req.getSession();
    hs.setAttribute("lokesh", l2);


    System.out.println(l2);
    return "Menubar";

}

@RequestMapping("/test")
public String hom(Model model, HttpServletRequest req) {


    return "test";

}

1 个解决方案

#1


th:include will pull and render whatever the th:fragment encompases.

th:include将拉动并渲染th:fragment包含的内容。

e.g.

    <div th:fragment="show_data">
<p>Hello Data<p>
<p><span th:text="${somedata}></span></p>
    </div>

the render will result in following being passed to the controller method:

渲染将导致以下传递给控制器​​方法:

<p>Hello Data<p>
<p><span th:text="${somedata}></span></p>

If the th:fragment contains variables e.g. ${somedata} which you want rendered on your main page, you must remember to pass that same variable to your main page otherwise it won't get rendered.

如果th:片段包含变量,例如要在主页上呈现的$ {somedata},您必须记住将相同的变量传递给主页,否则将无法呈现。

e.g.

public String main(Model model) {
model.addAttribute("somedata", "this is test data.");
return "main";
}

will result in render of:

将导致渲染:

// main page content
This is main page data.
// fragment content
Hello Data
this is test data
//continuation of main page content
blah blah blah

#1


th:include will pull and render whatever the th:fragment encompases.

th:include将拉动并渲染th:fragment包含的内容。

e.g.

    <div th:fragment="show_data">
<p>Hello Data<p>
<p><span th:text="${somedata}></span></p>
    </div>

the render will result in following being passed to the controller method:

渲染将导致以下传递给控制器​​方法:

<p>Hello Data<p>
<p><span th:text="${somedata}></span></p>

If the th:fragment contains variables e.g. ${somedata} which you want rendered on your main page, you must remember to pass that same variable to your main page otherwise it won't get rendered.

如果th:片段包含变量,例如要在主页上呈现的$ {somedata},您必须记住将相同的变量传递给主页,否则将无法呈现。

e.g.

public String main(Model model) {
model.addAttribute("somedata", "this is test data.");
return "main";
}

will result in render of:

将导致渲染:

// main page content
This is main page data.
// fragment content
Hello Data
this is test data
//continuation of main page content
blah blah blah