Getting error: Route() in Route cannot be applied to String

前端 未结 5 986
栀梦
栀梦 2021-01-05 18:48

I\'m designing a Java based MongoDB app and I\'ve ran into a snag when working with Spark.

package com.tengen;

import spark.Request;
import spark.Response;
         


        
5条回答
  •  天涯浪人
    2021-01-05 19:27

    Currently, Implementation of Spark Java framework needs to use directory out of Route. So you have to correct your code as follow:

    public static void main(String[] args) {
        spark.Spark.port(PortNumber);
        Spark.get("/", new Route() {
                public Object handle(Request request, Response response) throws Exception {
                    return "This is a sample page";
                }
            });
    }
    

    actually, "/" is the resource to your program. And if you want to change the default spark.Spark.port(PortNumber).

提交回复
热议问题