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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| package com.buubiu.controller;
import com.buubiu.entity.User; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping;
@Controller @RequestMapping("attr") public class AttrController {
@RequestMapping("test") public String test(Model model, HttpServletRequest request, HttpServletResponse response) {
String name = "buubiu";
User user = new User("111", "buubiu", 33, new Date());
User user1 = new User("222", "buubiu2", 43, new Date()); User user2 = new User("333", "buubiu333", 53, new Date()); List<User> users = Arrays.asList(user, user1, user2);
model.addAttribute("username", name); model.addAttribute("user",user); model.addAttribute("users", users);
return "attr"; }
@RequestMapping("test1") public String test1(HttpServletRequest request) throws UnsupportedEncodingException { String name = "buubiu中文";
User user = new User("111", "buubiu", 33, new Date()); request.getSession().setAttribute("user", user); return "redirect:/attr.jsp?name="+ URLEncoder.encode(name,"UTF-8"); } }
|