提交 0355ba06 编写于 作者: VenseChen's avatar VenseChen

105_修改注册控制类

上级 18eab5fb
package com.git.backend.controller; package com.git.backend.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.git.backend.common.Result; import com.git.backend.common.Result;
import com.git.backend.common.TelephoneJudege; import com.git.backend.common.TelephoneJudege;
import com.git.backend.entity.User; import com.git.backend.entity.User;
import com.git.backend.mapper.UserMapper; import com.git.backend.mapper.UserMapper;
import com.git.backend.service.UserService;
import com.git.backend.service.impl.UserServiceImpl; import com.git.backend.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.util.HashMap; import java.util.HashMap;
...@@ -20,12 +24,13 @@ import java.util.regex.Pattern; ...@@ -20,12 +24,13 @@ import java.util.regex.Pattern;
* @author 105_陈玮鑫 * @author 105_陈玮鑫
* *
* */ * */
@Controller @RestController
public class RegisterController { public class RegisterController {
private static UserMapper userMapper; @Autowired
public static boolean InsertUser(String phone,String password,String name,String address) UserService userService;
public boolean InsertUser(String phone,String password,String name,String address)
{ {
UserServiceImpl userService=new UserServiceImpl();
boolean flag = false; boolean flag = false;
User user=new User(); User user=new User();
user.setPhone(phone); user.setPassword(password); user.setPhone(phone); user.setPassword(password);
...@@ -33,26 +38,29 @@ public class RegisterController { ...@@ -33,26 +38,29 @@ public class RegisterController {
flag=userService.save(user); flag=userService.save(user);
return flag; return flag;
} }
public User getAttribute(String attributeValue)
{
QueryWrapper<User> wrapper=new QueryWrapper<>();
System.out.println(attributeValue);
wrapper.eq("phone",attributeValue);
User user=userService.getOne(wrapper);
return user;
}
@RequestMapping("/user/register") @RequestMapping("/user/register")
public Result register(@RequestParam("phone") String phone, @RequestParam("password") String password, @RequestParam("name") String name, @RequestParam("address") String address, Model model, HttpSession session) { public Result register(@RequestParam("phone") String phone, @RequestParam("password") String password, @RequestParam("name") String name, @RequestParam("address") String address) {
//如果用户名和密码正确 //如果用户名和密码正确
UserServiceImpl userService=new UserServiceImpl();
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
if (TelephoneJudege.isCellPhoneNo(phone)) { if (TelephoneJudege.isCellPhoneNo(phone)) {
session.setAttribute("LoginUser", phone);
session.setAttribute("name",name);
InsertUser(phone,password,name,address); InsertUser(phone,password,name,address);
//map.put("jump","redirect:/main.html") map.put("id",getAttribute(phone).getId());
map.put("id",LoginController.getAttribute("id",phone));
map.put("name",name); map.put("name",name);
map.put("phone",phone); map.put("phone",phone);
map.put("address",address); map.put("address",address);
return Result.success(200,"注册成功",map);//跳转到dashboard页面 return Result.success(200,"注册成功",map);//跳转到dashboard页面
}//如果用户名或者密码不正确 }//如果用户名或者密码不正确
else { else {
model.addAttribute("msg", "手机号码格式错误");//显示错误信息
//map.put("jump","index");
return Result.success(400,"注册失败",map); return Result.success(400,"注册失败",map);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册