scala、spring 和 scalate [英] scala, spring, and scalate

查看:68
本文介绍了scala、spring 和 scalate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 scala、spring、sitemesh 和 jspx/jstl 编写的 Web 项目.问题出在 jspx 上.我一直遇到希望类型为 java 集合类型的问题,因此我必须不断在 Scala/java 集合之间进行转换.有时我会忘记,我的观点会爆炸,等等.

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.

我想知道是否有一篇博客文章描述了从 jsp/jstl/jspx 迁移到 scalate 的方式/涉及的内容?因为否则切换似乎有点不知所措,不管现在烦人我认为jspx是.

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.

推荐答案

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

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 依赖:

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:

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 并开始翻译代码.为了访问模型对象,我在我的 scaml 文件顶部执行此操作:

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]

然后我只是遵循了诈骗文档.超级容易.唯一令人尴尬的是试图放入内联 javascript ......它抱怨缩进或其他东西.所以我把它移到了一个单独的文件中.

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.

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

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.

这篇关于scala、spring 和 scalate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆