<!-- 查询student_id是否存在 -->
<select id="getStudent_id" resultMap="studentMap" parameterType="int">
SELECT * from student where student_id = #{student_id}
</select>@RequestMapping("/studentID")
public Student getStudent_id(Integer student_id) {
Student student = userService.getStudent_id(student_id);
if (student==null){
System.out.println("没有");
}else{
System.out.println("有");
}
return student;
}function check() {//js表单验证方法
var text = document.getElementById("xh").value;//通过id获取需要验证的表单元素的值
if (text == "") {
alert("请输入学号!");//弹出提示
return false;//返回false(不提交表单)
}
if (!(/(^[1-9]\d*$)/.test(text))) {
alert("请输入学号!");//弹出提示
return false;//返回false(不提交表单)
}
var student_id=$("#student_id").val();
$.ajax({
url:"<%=basePath%>user/studentID",
type:"post",
data:{"student_id":student_id},
dataType:"json",
success:function(data){
if (data!=null ) {
alert("有");
}else if(data==null && username !=''){
alert("没有");
}
xmlhttp.open("GET","getcustomer.asp?q="+str,true);
xmlhttp.send();
//alert("啊啊啊");
}
});
return true;//提交表单
}
</script>
<body>
<div class="listDIV">
<table border="1" width="50%" height="50%" style="text-align: center;">
<form action="<%=basePath%>user/one" method="post">
<input type="text" id="xh" name="student_id" placeholder="根据学号查询">
<button class="glyphicon glyphicon-select" onclick="return check();">查询</button>
</form>我用ssm做的增删改查,搜索我想先校验一下数据库数据是否存在,存在就直接跳转查询,不存在就弹窗提示,中止提交表单,JS代码是我粘过来的,不会JS,有错误希望能告诉我如何改正,谢谢
3 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
form表单
<form action="<%=basePath%>user/one" method="post" onsubmit="return check(this)"> <input type="text" id="xh" name="student_id" placeholder="根据学号查询"> <button class="glyphicon glyphicon-select">查询</button> </form>
js表单校验
function check(form) {
if (form.student_id.value == '') {
alert("查无此人");
form.student_id.focus();
return false;
}
return true;
}java后端
@Controller
@RequestMapping("/user")
public class Xxx{
@RequestMapping("/one")
public Student getStudent_id(Integer student_id) {
}
}添加回答
举报
0/150
提交
取消
