新增用例

This commit is contained in:
罗祥
2019-01-14 01:09:21 +08:00
parent 443b1b4b37
commit ee4aae665c
29 changed files with 36 additions and 36 deletions

View File

@ -0,0 +1,17 @@
package com.heibaiying.bean;
import lombok.Data;
import java.io.Serializable;
/**
* @author : heibaiying
*/
@Data
public class User implements Serializable {
private long userId;
private String username;
private String password;
}

View File

@ -0,0 +1,38 @@
package com.heibaiying.controller;
import com.heibaiying.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @author : heibaiying
* @description : 登录
*/
@Controller
public class LoginController {
@RequestMapping
public String index(){
return "index";
}
@RequestMapping("home")
public String home(){
return "home";
}
@PostMapping("login")
public String login(User user, HttpSession session, HttpServletRequest request, Model model){
// 随机生成用户id
user.setUserId(Math.round(Math.floor(Math.random() *10*1000)));
// 将用户信息保存到id中
session.setAttribute("USER",user);
return "redirect:home";
}
}