上一篇----springboot - mybatis连接多数据源(动态)
在做好数据源的切换下,将我们的操作界面化,这里我使用的freemaker进行操作
a.ftl
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8">
<title>mysql</title>
</head>
<body>
<#--<font color="red"><h3>${error!}</h3> </font>-->
<h1>数据库展示</h1>
<form action="/ifindAll" method="get">
<input type="submit" id="submit0" value="首页"/>
</form>
<h4>查找一个id</h4>
<form action="/seletePersonId1" method="get">
<input type="number" id="id" name="id" required/>
<input type="submit" id="submit1" value="查找"/>
</form>
<h3>数据查找</h3>
<table>
<tr>
<td>name</td>
<td>username</td>
<td>university</td>
</tr>
<tr>
<form action="/findmore">
<td><input type="text" id="name" name="name" width="10px" placeholder="name"/></td>
<td><input type="text" id="username" name="username" width="10px" placeholder="username"/></td>
<td><input type="text" id="university" name="university" width="10px" placeholder="university"/></td>
</tr>
<tr>
<td><input type="submit" id="submit" value="查找"/></td>
</tr>
</table>
</form>
<h4>增加一个记录</h4>
<form action="/savePerson1" method="get">
<input type="number" id="addid" name="id" placeholder="添加id" required/><font color="#a9a9a9" maxlength="3">必填</font><br/>
<input type="text" id="addusername" name="username" placeholder="username" required/><font color="#a9a9a9">必填</font><br/>
<input type="password" id="addpassword" name="password" placeholder="password" required/><font color="#a9a9a9">必填</font><br/>
<input type="text" id="addname" name="name" placeholder="name" required/><font color="#a9a9a9">必填</font><br/>
<input type="text" id="adduniversity" name="university" placeholder="university"/><br/>
<input type="submit" id="submit4" value="提交"/>
</form>
<br/><br/>
<table border="1" th:width="200">
<tr th:width="50" th:height="15">
<td>id</td>
<td>username</td>
<td>password</td>
<td>name</td>
<td>university</td>
<td>删</td>
<td>改</td>
</tr>
<#if listres ??>
<#list listres as items>
<tr>
<td width="30">${items.id}</td>
<td width="30">${items.username}</td>
<td width="30">${items.password}</td>
<td width="30">${items.name}</td>
<td width="30">${items.university}</td>
<td>
<form action="/deleteName1" method="get">
<input value="${items.id}" name="delid" style="display: none">
<input value="删除" type="submit"></form>
</td>
<td>
<form action="/toupdpage" method="get">
<input value="${items.id}" name="updid" style="display: none" >
<input value="修改" type="submit" src="/updpage"></form>
</td>
</tr>
</#list>
</#if>
</table>
</body>
</html>
<#--
<h4>查找name</h4>
<form action="/seletePerson1" method="get">
<input type="text" id="name" name="name"/>
<input type="submit" id="submit2" value="查找"/>
</form>
<h4>查找username</h4>
<form action="/findByname1" method="get">
<input type="text" id="username" name="username"/>
<input type="submit" id="submit3" value="查找"/>
</form>
<h4>查找university</h4>
<form action="/seleteUniversity" method="get">
<input type="text" id="university" name="university"/>
<input type="submit" id="submit4" value="查找"/>
</form>-->
updpage.ftl数据修改界面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8">
<title>修改页面</title>
</head>
<body>
<h2>修改数据</h2>
<hr/>
<form action="/updaPerson1" method="get">
<input type="number" id="id" name="id" value="${id}" required/><br/>
<input type="number" id="oldid" name="oldid" value="${id}" style="display: none"/>
<input type="text" id="updusername" name="username" placeholder="username" required/><br/>
<input type="password" id="updpassword" name="password" placeholder="password" required/><br/>
<input type="text" id="updname" name="name" placeholder="name" required/><br/>
<input type="text" id="upduniversity" name="university" placeholder="university" required/><br/>
<input type="submit" id="submit" value="提交"/>
</form>
</body>
</html>
success.ftl消息返回页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多数据源展示</title>
</head>
<body>
<span style="font-size:24px;">
<meta http-equiv="refresh" content="3;URL=http://localhost:8080/ifindAll?"> </span>
<#if error ??>
<font color="red"><h4>抱歉, ${error!}</h4></font><br>
<h4>即将返回主页,你可以直接<a href="http://localhost:8080/ifindAll?">点击</a>返回 </h4>
<#else>
<h4>操作成功,即将返回主页,你可以直接<a href="http://localhost:8080/ifindAll?">点击</a>返回 </h4>
</#if>
</body>
</html>
下面我们到http://localhost:8080/ifindAll?这个链接中查看数据,
这个页面直接显示所有的数据
查找ID是3的记录
这里username,password是test这个数据源里表名是user的数据
name,university是lxy2018数据库中表名是lxy2018_table的数据
模糊查找
增加记录
修改id是6的数据
删除id是4的数据
OK,大功告成,源码点击这里