localhost:8080/返回状态404-Spring
这是我的代码:localhost:8080/返回状态404-Spring,spring,spring-mvc,Spring,Spring Mvc,这是我的代码: @Controller @RequestMapping("/") public class MerchantsController { @Autowired MerchantsService merchantsService; @Autowired ProductsService productsService; @Autowired OrdersService ordersService; @RequestMapp
@Controller
@RequestMapping("/")
public class MerchantsController {
@Autowired
MerchantsService merchantsService;
@Autowired
ProductsService productsService;
@Autowired
OrdersService ordersService;
@RequestMapping(value = "/merchants", method = RequestMethod.GET)
public ModelAndView showMerchantsList() {
ModelAndView modelAndView = new ModelAndView("merchantsList");
List<Merchant> merchants = merchantsService.getMerchantsList();
for (Merchant merchant : merchants) {
if(merchant.getOrder_type() == OrderType.NO_ORDERING){
merchant.setOrderUntil(Time.valueOf("00:00:00"));
}
}
modelAndView.addObject("merchants", merchants);
return modelAndView;
}
@控制器
@请求映射(“/”)
公共类商品控制器{
@自动连线
商品服务;
@自动连线
产品服务产品服务;
@自动连线
订单服务订单服务;
@RequestMapping(value=“/merchants”,method=RequestMethod.GET)
公共模型和视图showMerchantsList(){
ModelAndView ModelAndView=新的ModelAndView(“商品列表”);
List merchants=merchantsService.getMerchantsList();
用于(商户:商户){
if(merchant.getOrder\u type()==OrderType.NO\u ORDERING){
商户.setOrderUntil(时间.valueOf(“00:00:00”));
}
}
modelAndView.addObject(“商家”,商家);
返回模型和视图;
}
据我所知,当我向localhost:8080/发送请求时,它应该会打开localhost:8080/商户,但它不起作用。有人有什么建议吗?当您向localhost:8080/商户发送请求时,将调用showMerchantsList方法。此方法将再次重定向localhost:8080/商户。但是如果您希望以localhost:8080/并将您指向localhost:8080/merchants,然后您应该创建另一个方法,如下所示:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView showMerchantsListWithoutRequestMapping() {
ModelAndView modelAndView = new ModelAndView("merchantsList");
List<Merchant> merchants = merchantsService.getMerchantsList();
for (Merchant merchant : merchants) {
if(merchant.getOrder_type() == OrderType.NO_ORDERING){
merchant.setOrderUntil(Time.valueOf("00:00:00"));
}
}
modelAndView.addObject("merchants", merchants);
return modelAndView;
}
@RequestMapping(value=“/”,method=RequestMethod.GET)
公共模型和视图showMerchantsListWithoutRequestMapping(){
ModelAndView ModelAndView=新的ModelAndView(“商品列表”);
List merchants=merchantsService.getMerchantsList();
用于(商户:商户){
if(merchant.getOrder\u type()==OrderType.NO\u ORDERING){
商户.setOrderUntil(时间.valueOf(“00:00:00”));
}
}
modelAndView.addObject(“商家”,商家);
返回模型和视图;
}
当您以正常方式调用localhost:8080/时,此方法将您重定向到localhost:8080/merchants
@Controller
public class MerchantsController {
@Autowired
MerchantsService merchantsService;
@Autowired
ProductsService productsService;
@Autowired
OrdersService ordersService;
@RequestMapping(value = "/merchants", method = RequestMethod.GET)
public ModelAndView showMerchantsList() {
ModelAndView modelAndView = new ModelAndView("merchantsList");
List<Merchant> merchants = merchantsService.getMerchantsList();
for (Merchant merchant : merchants) {
if(merchant.getOrder_type() == OrderType.NO_ORDERING){
merchant.setOrderUntil(Time.valueOf("00:00:00"));
}
}
modelAndView.addObject("merchants", merchants);
return modelAndView;
}
@控制器
公共类商品控制器{
@自动连线
商品服务;
@自动连线
产品服务产品服务;
@自动连线
订单服务订单服务;
@RequestMapping(value=“/merchants”,method=RequestMethod.GET)
公共模型和视图showMerchantsList(){
ModelAndView ModelAndView=新的ModelAndView(“商品列表”);
List merchants=merchantsService.getMerchantsList();
用于(商户:商户){
if(merchant.getOrder\u type()==OrderType.NO\u ORDERING){
商户.setOrderUntil(时间.valueOf(“00:00:00”));
}
}
modelAndView.addObject(“商家”,商家);
返回模型和视图;
}
我以愚蠢的方式理解您的要求:
@Controller
public class MerchantsController {
@Autowired
MerchantsService merchantsService;
@Autowired
ProductsService productsService;
@Autowired
OrdersService ordersService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView showMerchantsList() {
ModelAndView model=new ModelAndView("redirect:/merchants");
return model;
}
@RequestMapping(value = "/merchants", method = RequestMethod.GET)
public ModelAndView showMerchantsList() {
ModelAndView modelAndView = new ModelAndView("merchantsList");
List<Merchant> merchants = merchantsService.getMerchantsList();
for (Merchant merchant : merchants) {
if(merchant.getOrder_type() == OrderType.NO_ORDERING){
merchant.setOrderUntil(Time.valueOf("00:00:00"));
}
}
modelAndView.addObject("merchants", merchants);
return modelAndView;
}
@控制器
公共类商品控制器{
@自动连线
商品服务;
@自动连线
产品服务产品服务;
@自动连线
订单服务订单服务;
@RequestMapping(value=“/”,method=RequestMethod.GET)
公共模型和视图showMerchantsList(){
ModelAndView模型=新的ModelAndView(“重定向:/merchants”);
收益模型;
}
@RequestMapping(value=“/merchants”,method=RequestMethod.GET)
公共模型和视图showMerchantsList(){
ModelAndView ModelAndView=新的ModelAndView(“商品列表”);
List merchants=merchantsService.getMerchantsList();
用于(商户:商户){
if(merchant.getOrder\u type()==OrderType.NO\u ORDERING){
商户.setOrderUntil(时间.valueOf(“00:00:00”));
}
}
modelAndView.addObject(“商家”,商家);
返回模型和视图;
}
注意:因为
/
总是指向根。你是在谈论重定向吗?如果你调用/
,就没有重定向,你必须调用/merchants
,或者如果你想从根目录重定向到商家。重定向:你试过本地主机:8080/ApplicationContext/merchants
?你能解释一下吗在我看来,当我向localhost:8080/发送请求时,它如何打开localhsot:8080/商户?