my.ctr.MainController.java Source code

Java tutorial

Introduction

Here is the source code for my.ctr.MainController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package my.ctr;

import com.eq.mavenproject5.TownsGame;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Eduard
 */

@Controller
public class MainController {
    @Autowired
    TownsGame gameService;

    @RequestMapping("test.do")
    ModelAndView test() {
        ModelAndView mv = new ModelAndView("testview");
        mv.addObject("towns", gameService);
        return mv;
    }

    @RequestMapping("add.do")
    ModelAndView test(String name) {
        ModelAndView mv = new ModelAndView("testview");
        if (gameService.addTown(name) == false) {
            mv.setViewName("redirect:error.html");
        }
        mv.addObject("lastTown", gameService.getLastTown());
        mv.addObject("gameHistory", gameService.getGameHistory());
        return mv;
    }
}