ua.com.rocketlv.spb.MainController.java Source code

Java tutorial

Introduction

Here is the source code for ua.com.rocketlv.spb.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 ua.com.rocketlv.spb;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ua.com.rocketlv.spb.model.Users;
import ua.com.rocketlv.spb.model.Usersadd;

/**
 *
 * @author rocketlv
 */
@Controller
public class MainController {
    @Autowired
    Store store;

    public void setStore(Store store) {
        this.store = store;
    }

    @Autowired
    UsersRepository repository;

    public void setRepository(UsersRepository repository) {
        this.repository = repository;
    }

    @Autowired
    MessageSource messages;

    public void setMessages(MessageSource messages) {
        this.messages = messages;
    }

    @RequestMapping("/")
    public String index(Model model) {
        store.setAdminAccount("?   ??  !");
        return "main";
    }

    @RequestMapping("/add")
    public String greeting(@RequestParam(value = "name", required = true, defaultValue = "------") String name,
            @RequestParam(value = "address", required = true, defaultValue = "------") String address,
            @RequestParam(value = "phone", required = true, defaultValue = "------") String phone, Model model) {
        model.addAttribute("name", name);
        Users users = new Users(name, address, phone);
        users.getUsersadd().add(new Usersadd("test information", users));
        users.getUsersadd().add(new Usersadd(" server ", users));
        users.getUsersadd().add(new Usersadd(" individual ", users));
        repository.save(users);
        return "greeting";
    }

}