springboot 我向数据库获取了用户密码,和api传递的参数进行判断。但结构为false。我单独输出出来结果也是一样的。求解!
package com.example.demo.content;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
//跨域问题
@CrossOrigin
public class content {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/login")
// 传递两个参数
public Object login(@RequestParam(value = "username", required = true) String username, @RequestParam(value = "userpwd", required = true) String userpwd) {
// 设置sql语句
String sql = "select * from userdata where username = " + "'" + username + "'";
// 执行sql语句并返回map
Map<String, Object> map = jdbcTemplate.queryForMap(sql);
// 两值
System.out.println(userpwd + "----" + map.get("userpwd"));
// 判断密码是否正确
if (userpwd == map.get("userpwd")) {
return true;
} else {
return false;
}
}
}
false 那就是密码不正确,检查检查密码相关的是否错误
以上仅供参考,希望对题主有所帮助!