我正在使用引导程序模板和弹簧启动,我想测试控制器,因为我编写了一个简单的restfull服务,它重新调整模板的索引页面,但它不起作用,它给了我一个错误。< / p>
这是项目的架构
这是我的控制器
package demo.controllers;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.view.RedirectView;
import demo.connection.SingletonConnection;
import demo.dao.IDatabase;
import demo.dao.IEntities;
import demo.entities.DB;
@RestController
public class DatabaseController implements ErrorController{
private static final String PATH = "/error";
protected Connection conn;
@Autowired
private IDatabase db;
@Autowired
private IEntities entities;
// En cas d'érreur
@RequestMapping(value = PATH)
public String error() {
return "Error";
}
@Override
public String getErrorPath() {
return PATH;
}
@RequestMapping(value="/")
public String index(Model model){
return "pages/index.html";
}
}
运行应用程序时