[英]springmvc using json response error
I have the following controller in springmvc. 我在springmvc中有以下控制器。
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! the client locale is "+ locale.toString());
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "main";
}
}
getting following error when i request to http://localhost:8080/Woodcutter/
url 当我请求到
http://localhost:8080/Woodcutter/
网址时出现以下错误
You have two methods home(String)
and external_page(String)
in HomeController
mapped to the same url http://localhost:8080/Woodcutter/
. 您在
HomeController
有两个方法home(String)
和external_page(String)
映射到相同的URL http://localhost:8080/Woodcutter/
。 You can map only one method mapped to a particular URL with HTTP method (GET / POST), That's the ambiguity. 您只能使用HTTP方法(GET / POST)将一种方法映射到特定的URL,这就是模棱两可。 Please change the URL for one of the method or remove one.
请更改其中一种方法的网址或删除其中一种。 How can a request be delegated to two methods matching the URL and HTTP method?
如何将请求委托给与URL和HTTP方法匹配的两个方法? Think.
认为。
这是因为两个方法都指向同一个URL,所以您的控制器感到困惑。您不能拥有两个相同的URL路径,这将导致模棱两可的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.