update LoginRegisterController

master
ziyonghong 5 years ago
parent 5f6ff0f9ac
commit 603d85f591

@ -53,6 +53,27 @@
</exclusions>
</dependency>
<!-- mysql?jpa-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- spark?-->
<dependency>
<groupId>org.apache.spark</groupId>

@ -1,22 +1,56 @@
// package com.cmkg.cmkg.Controller;
package com.cmkg.cmkg.Controller;
// import com.cmkg.cmkg.database.ReturnData;
// import org.springframework.data.repository.query.Param;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RequestParam;
import com.cmkg.cmkg.database.user;
import com.cmkg.cmkg.repository.Login_Register_Repository;
import com.cmkg.cmkg.server.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
// @RequestMapping("/request")
// public class LoginRegisterController {
@RestController
@RequestMapping("/request")
public class LoginRegisterController {
// @RequestMapping("/login")
// public ReturnData LoginGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("password") String password){
@Autowired
Login_Register_Repository login_register_repository;
// }
@RequestMapping("/login")
public ReturnData LoginGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("password") String password){
ReturnData returnData=new ReturnData();
user user=login_register_repository.findById(phonenumber).orElse(null);
if(user==null){
returnData.setMsg("该用户不存在");
}
else{
if(user.getPassword().equals(password)){
returnData.setMsg("登录成功");
returnData.setData(user.getUsername());
}else{
returnData.setData("密码错误,登陆失败");
}
}
return returnData;
// @RequestMapping("/register")
// public ReturnData RegisterGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("username") String username,@RequestParam("password") String password,
// @RequestParam("region") String region, @RequestParam("age") Long age){
}
// }
// }
@RequestMapping("/register")
public ReturnData RegisterGet(@RequestParam("phonenumber") String phonenumber, @RequestParam("username") String username,@RequestParam("password") String password,
@RequestParam("region") String region, @RequestParam("age") Integer age,@RequestParam("sex") Integer sex){
ReturnData returnData=new ReturnData();
user user=login_register_repository.findById(phonenumber).orElse(null);
if(user==null) {
login_register_repository.save(new user(phonenumber, username, password, age, sex, region));
returnData.setCode(200);
returnData.setMsg("注册成功");
returnData.setData(null);
}else{
returnData.setCode(404);
returnData.setMsg("注册失败");
returnData.setData(null);
}
return returnData;
}
}

Loading…
Cancel
Save