scala、spring 和 scalate

发布于 2024-11-05 08:35:51 字数 236 浏览 0 评论 0原文

我有一个用 scala、spring、sitemesh 和 jspx/jstl 编写的 Web 项目。问题出在 jspx 上。我一直遇到问题,它希望类型是 java 集合类型,所以我必须继续在 scala/java 集合之间进行转换。有时我会忘记,我的观点会爆炸,等等。

我想知道是否有一篇博客文章描述了如何/从 jsp/jstl/jspx 迁移到 scalate?因为否则的话,切换起来似乎有点难以承受,不管现在我认为 jspx 有多烦人。

I have a web project written in scala, spring, sitemesh, and jspx/jstl. The problem is with the jspx. I keep running into issues where it wants the types to be java collection types and so I have to keep converting between scala/java collections. And sometimes I forget, and my view blows up, etc.

I'm wondering if there's a blog post out there somewhere that describes how/what's involved to migrate from jsp/jstl/jspx to scalate? Because otherwise it just seems a bit overwhelming to switch, no matter now annoying I think jspx is.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉宸 2024-11-12 08:35:51

好吧,所以我冒险尝试一下,只是想看看整个事情是如何运作的。事实证明这相当容易。以下是任何感兴趣的人的步骤:

Maven pom 依赖项:

    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-compiler</artifactId>
        <version>${scala.version}</version>
    </dependency>

    <!-- scalate templating engine -->
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-spring-mvc</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-wikitext</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-page</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalamd</groupId>
        <artifactId>scalamd</artifactId>
        <version>${scalamd.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-test</artifactId>
        <version>${scalate.version}</version>
        <scope>test</scope>
    </dependency>

mvc-servlet.xml:

<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/>
<bean id="scalateViewResolver" class="org.fusesource.scalate.spring.view.ScalateViewResolver"
    p:order="1" p:prefix="/WEB-INF/view/" p:suffix=".scaml" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
     p:order="2" p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/WEB-INF/view/" p:suffix=".jspx" />

然后我重命名了一些 jspx 并开始翻译代码。为了访问模型对象,我在我的诈骗文件顶部执行此操作:

-@ var x:String
-@ var y:List[com.xxx.model.MyModelObject]

然后我只是按照诈骗文档进行操作。超级简单。唯一尴尬的是尝试放入内联 javascript...它抱怨缩进或其他问题。所以我把它移到一个单独的文件中。

根本不必删除 sitemesh(但将来只要我准备好就可以删除),并且我可以在闲暇时迁移 jspx 文件。再简单不过了。

Ok so I took the plunge and just tried to see how this whole thing works. It turns out to be fairly easy. Here's the steps for anyone interested:

Maven pom dependencies:

    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-compiler</artifactId>
        <version>${scala.version}</version>
    </dependency>

    <!-- scalate templating engine -->
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-spring-mvc</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-wikitext</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-page</artifactId>
        <version>${scalate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalamd</groupId>
        <artifactId>scalamd</artifactId>
        <version>${scalamd.version}</version>
    </dependency>
    <dependency>
        <groupId>org.fusesource.scalate</groupId>
        <artifactId>scalate-test</artifactId>
        <version>${scalate.version}</version>
        <scope>test</scope>
    </dependency>

mvc-servlet.xml:

<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator"/>
<bean id="scalateViewResolver" class="org.fusesource.scalate.spring.view.ScalateViewResolver"
    p:order="1" p:prefix="/WEB-INF/view/" p:suffix=".scaml" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
     p:order="2" p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/WEB-INF/view/" p:suffix=".jspx" />

Then I renamed some jspx and started translating code. To get access to model objects I do this at the top of my scaml file:

-@ var x:String
-@ var y:List[com.xxx.model.MyModelObject]

Then I just followed the scaml docs. Super easy. The only thing that was awkward was trying to put inline javascript...it complained about indentation or something. So I moved that out to a separate file.

Didn't have to remove sitemesh at all (but I can in the future whenever I'm ready), and I can migrate jspx files at my leisure. Couldn't be easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文