login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/jdbc1" method="get">
<input type="text" name="username">
<input type="password" name="userpassword">
<input type="submit" value="提交">
</form>
</body>
</html>
lianjie.contrller
lianjie.controller
由于这种方法返回的是List,所以用了一个比较无厘头的比较密码方法
将前台传来的密码也加上{},再和数据库取出的list比较
package aa.mysql428.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
@Controller
public class lianjie {
@Autowired
JdbcTemplate jdbcTemplate;
@ResponseBody
@GetMapping("/jdbc1")
//public Map<String, Object> map(@RequestParam("username") String name , @RequestParam("userpassword") String password) {
public String map(@RequestParam("username") String name , @RequestParam("userpassword") String password) {
List<Map<String, Object>> list = jdbcTemplate.queryForList("select password1 from user where username1="+name);
String a= list.get(0).toString();
String b="{password1="+password+"}";
if(b.equals(a)){
return "successful";
}
else{
return "fail";
}
}
}
aplication.yml
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/customers?serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
sprintboot如何接收html表单传参
public String map(@RequestParam("username") String name , @RequestParam("userpassword") String password)
将取出的List转换为字符串
String a= list.get(0).toString();
本文介绍了如何使用Spring Boot开发一个简单的HTML登录页面,表单数据通过GET请求发送到后端,后端利用JDBC查询数据库并进行密码匹配。展示了@Autowired注解注入JdbcTemplate及Controller中处理GET请求的方法。
2643

被折叠的 条评论
为什么被折叠?



