@Test
public void testSelectUser() throws Exception {
long id = 1;
User user = dao.selectUser(id);
System.out.println(user.getUsername());
}
}
运行后结果应该是会在控制台输出id为1的用户名,没成功的话就找BUG去吧...
继续新建个页面来测试springmvc和mybatis
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<script>
function selectUser() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("test").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "user/showUser.do", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("id=1");
}
</script>
<body>
<p>Hello World!</p>
<button type="button">onclick test</button>
</body>
</html>
新建完成后配置项目运行环境,点击Run-Edit Configurations...
点击加号新建运行环境,选择Tomcat Server-Local
选中新建好的服务器,右边选择Deployment,点击加号-Atifact...
选择第二项
然后在右边Application context配置你的项目名
最后运行项目,在打开的页面中点击按钮测试,成功的话会在页面上显示id为1的用户信息