springbooot
前言
创建一个简单的操作mysql数据库的springboot应用程序
以下是本篇文章正文内容,下面案例可供参考
步骤
填写application.properties
因为引入了数据库所以必须要在这里填写数据库驱动等相关的内容
代码如下(示例):
server.address=“Ip地址”
server.port=“端口号”
spring.datasource.url=jdbc:mysql://localhost:3306/{这里填写数据库名}?characterEncoding=utf8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=“数据库用户名一般为root”
spring.datasource.password=“数据库密码”
spring.datasource.tomcat.driver-class-name=com.mysql.jdbc.Driver //加载数据库驱动
spring.thymeleaf.prefix=classpath:/templates/
spring.resources.static-locations=classpath:/static/,classpath:/templates/
上代码
//控制层
@Controller
public class MsController{
//传输据
@ResponseBody
@RequestMapping("/index")
public String Login(String name){
return name;
}
//加载页面
@RequestMapping("/main")
public String m(){
return "index";
}
}
}
//前端 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<script src="js/jquery-3.4.0.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
url:'/main',
data:{
name:'hh',
}
success:function(data){
console.log(data); //打印到控制台
$("#name").html(data);
}
})
)
</script>
<body>
name :<div id="name"></div>
</body>
</html>