斯卡拉,春天和树叶

Kev*_*vin 3 scala spring-mvc scalate

我有一个用scala,spring,sitemesh和jspx/jstl编写的web项目.问题在于jspx.我一直在遇到需要类型为java集合类型的问题,因此我必须继续在scala/java集合之间进行转换.有时我会忘记,我的观点会爆炸,等等.

我想知道是否有某个博客文章描述了从jsp/jstl/jspx迁移到scalate的方式/内容是什么?因为否则它只是看起来有点压倒性的切换,不管现在烦人我认为jspx是.

Kev*_*vin 8

好的,所以我冒险尝试看看整个过程是如何工作的.事实证明这很容易.以下是感兴趣的人的步骤:

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>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

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

-@ var x:String
-@ var y:List[com.xxx.model.MyModelObject]
Run Code Online (Sandbox Code Playgroud)

然后我就跟着scaml docs了.超级容易.唯一令人尴尬的是尝试使用内联javascript ...它抱怨缩进或其他什么.所以我把它移到了一个单独的文件中.

根本不需要删除sitemesh(但是我可以在将来每当我准备好的时候),并且我可以在闲暇时迁移jspx文件.不可能更容易.