FrontController.java 882 Bytes
Newer Older
Javier Ferreira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
package com.test.demo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class FrontController {
	@RequestMapping("/test")
	public String viewTest(@RequestParam String name,HttpServletRequest req) {
		HttpSession session = req.getSession();
		session.setAttribute("name", name);
		return "test";
		
	}
	@RequestMapping("/test/{name}")
	public ModelAndView viewPathTest(@PathVariable String name,HttpServletRequest req) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("name",name);
		mv.setViewName("test");
		return mv;
		
	}
}