我正在使用mvc + mongodb构建一个非常简单的Spring启动应用程序.我使用Spring初始化程序来创建具有web,thymeleaf和mongo依赖项的proj.我有一个控制器,一个模型和一个视图,但我在尝试执行应用程序时仍然遇到错误:
Description:
Field repo in com.example.CustomerController required a bean named 'mongoTemplate' that could not be found.
Action:
Consider defining a bean named 'mongoTemplate' in your configuration.
Run Code Online (Sandbox Code Playgroud)
CustomerController:
import model.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Created by Hello on 25/04/2017.
*/
@Controller
@RequestMapping("/home")
public class CustomerController {
@Autowired
CustomerMongoRepo repo;
@RequestMapping(value = "/home", method= RequestMethod.GET)
public String viewingHome(Model model){
//initDB();
model.addAttribute("key", "THIS IS FROM THE MODEL");
return "homepage";
}
}
Run Code Online (Sandbox Code Playgroud)
CustomerMongoRepo:
import …Run Code Online (Sandbox Code Playgroud) 我正在使用带有mvc的Spring启动.我有一个json模式用于请求和响应.基本上用户将数据(在json中)发布到url,控制器执行其逻辑并返回json.我很难回到json.到目前为止,我有几个观点(在百里香中)有硬编码的反应,我不想要.我只想使用一个可以编辑并发送回客户端的对象.反应非常简单.这是响应的模式:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"message":{
"minLength":1,
"type":"string"
}
},
"required": [
"message"
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个类型响应的对象,它符合我的响应json架构.我基本上想要将此对象输出到客户端.但不确定我的控制器如何返回一个String,这个字符串通常是html页面的名称.