|
|
@ -2,10 +2,10 @@ package demo.liaofeifei; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
@ -56,4 +56,69 @@ public class login { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/userlogin") |
|
|
|
|
|
|
|
public Map<String, Object> userlogin(@RequestBody HashMap<String, Object> params) { |
|
|
|
|
|
|
|
HashMap<String, Object> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
String username = (String) params.get("username"); |
|
|
|
|
|
|
|
String password = (String) params.get("password"); |
|
|
|
|
|
|
|
if (username == null || password == null){ |
|
|
|
|
|
|
|
hashMap.put("code", 500); |
|
|
|
|
|
|
|
hashMap.put("msg", "用户名或密码不能为空"); |
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String sql = "SELECT userNo, userName, tel, addr,gender FROM user_info WHERE userNo = ? AND passwd = ?"; |
|
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, username, password); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (list == null || list.size() == 0) { // 查询不到用户返回空Map
|
|
|
|
|
|
|
|
hashMap.put("code", 500); |
|
|
|
|
|
|
|
hashMap.put("msg", "用户名或密码错误"); |
|
|
|
|
|
|
|
return new HashMap<>(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
hashMap.put("code", 200); |
|
|
|
|
|
|
|
hashMap.put("msg", "登录成功"); |
|
|
|
|
|
|
|
hashMap.put("data", list.get(0)); |
|
|
|
|
|
|
|
return hashMap; // 返回用户信息,不包含密码
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/userRegister") |
|
|
|
|
|
|
|
public Map<String, Object> userRegister(@RequestBody HashMap<String, Object> params) { |
|
|
|
|
|
|
|
HashMap<String, Object> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
String username = (String) params.get("username"); |
|
|
|
|
|
|
|
String password = (String) params.get("password"); |
|
|
|
|
|
|
|
if (username == null || password == null) { |
|
|
|
|
|
|
|
hashMap.put("code", 500); |
|
|
|
|
|
|
|
hashMap.put("msg", "用户名或密码不能为空"); |
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查用户名是否已经存在
|
|
|
|
|
|
|
|
String checkSql = "SELECT COUNT(*) FROM user_info WHERE userNo = ?"; |
|
|
|
|
|
|
|
Integer count = jdbcTemplate.queryForObject(checkSql, new Object[]{username}, Integer.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (count != null && count > 0) { |
|
|
|
|
|
|
|
hashMap.put("code", 500); |
|
|
|
|
|
|
|
hashMap.put("msg", "用户名已存在"); |
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 进行注册
|
|
|
|
|
|
|
|
String insertSql = "INSERT INTO user_info (userNo, passwd) VALUES (?, ?)"; |
|
|
|
|
|
|
|
int rowsAffected = jdbcTemplate.update(insertSql, username, password); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rowsAffected > 0) { |
|
|
|
|
|
|
|
hashMap.put("code", 200); |
|
|
|
|
|
|
|
hashMap.put("msg", "注册成功"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
hashMap.put("code", 500); |
|
|
|
|
|
|
|
hashMap.put("msg", "注册失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return hashMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|