WelcomeController.java
2.11 KB
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
package com.project.demo.web;
import com.project.demo.domain.Users;
import com.project.demo.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping(value = "/welcome")
public class WelcomeController {
@Autowired
private UsersService usersService;
//显示首页
@RequestMapping("/index")
public String index() {
return "/index";
}
@RequestMapping(method = RequestMethod.GET)
public String findAll(){
return "/welcome/index";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public Object login( HttpSession session,HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) {
String queryString = httpServletRequest.getQueryString();
String[] strs=queryString.split("[&]");
String[] strs1=strs[0].split("[=]");
String[] strs2=strs[1].split("[=]");
String result = usersService.checkPassWord(strs1[1],strs2[1]);
//System.out.println(strs1[1]+"|b|"+strs2[1]);
if(result.equals("true")){
Users users = usersService.findByMobile(strs1[1]);
session.setAttribute("users", users);
return "redirect:already";
}else{
return "redirect:again";
}
}
//跳转登录后首页
@RequestMapping("/already")
public String userIndex() {
return "/welcome/index";
}
//
@RequestMapping("/again")
public void nouserIndex() {
System.out.println("进入again");
}
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(final HttpSession session){
Users users = (Users) session.getAttribute("users");
session.removeAttribute("users");
return "redirect:/";
}
}