简体   繁体   English

如何抑制 freemarker 模板文件中的其他内容?

[英]How do I suppress additional content in freemarker template file?

My company uses java lite (active web) and freemarker templates for display in some legacy web pages.我的公司使用 java lite(活动网络)和 freemarker 模板在一些旧版 web 页面中显示。 I wrote an active web AppController which is forwarding to an ftl display file (freemarker template) and I'm able to see the 'hello world' content.我写了一个活跃的 web AppController,它转发到一个 ftl 显示文件(freemarker 模板),我可以看到“hello world”内容。 However somehow the page is also getting our standard web site header and footer content and I have no idea how to suppress that or where to look.然而不知何故,该页面也获得了我们的标准 web 站点 header 和页脚内容,我不知道如何抑制它或在哪里查看。 Is there some global configuration for javalite that says to include headers and footers for all pages and can it be supressed? javalite 是否有一些全局配置,它说包括所有页面的页眉和页脚,并且可以抑制它吗?

public class MfaController extends AppController {
    @GET
    public void registration()  {
        //does nothing
    }
}

registration.ftl:注册.ftl:

<html>
<body>hello world</body>
</html>

JavaLite is not using configuration files. JavaLite 不使用配置文件。 Instead it uses conventions.相反,它使用约定。 What you observe is a default behavior.您观察到的是默认行为。 The default layout located in默认布局位于

src/main/webapp/WEB-INF/views/layouts/default_layout.ftl

is applied to all web pages, unless you tell the framework you do not need it.适用于所有 web 页面,除非您告诉框架您不需要它。

If you do not want a layout, you can turn it off by overriding a getLayout() method:如果您不需要布局,可以通过覆盖getLayout()方法将其关闭:

public class MfaController extends AppController {

    public void registration()  {
        //does nothing
    }
    public String getLayout(){
        return null;
    }
}

A alternative solution will look like this:替代解决方案如下所示:

public class MfaController extends AppController {
    public void registration()  {
         render().noLayout();
    }
}

Also, the @GET annotation is redundant, all actions are GET by default if public.此外, @GET注释是多余的,如果公开,则默认情况下所有操作都是 GET。

Here is the docs: https://javalite.io/views#default-layout这是文档: https://javalite.io/views#default-layout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM