发表于: 2018-04-05 23:10:44
1 618
今天要在页面输入id,然后查出来student其他的数据
首先,确定sql语句,写在mapper里面
select * from student where id = 293;
然后在控制器里面确定输入查询的页面,暂定确定为:/student/toget
然后写出Controller里面的接口
@RequestMapping(value="/student/toget",method=RequestMethod=GET)
public String toGet(){
return "toget"
}
然后新建一个toget页面,意思也就是我在页面的text框里面输入id数值,点击搜索,搜索的值是value,如果写name的话,会依然显示提交。这些值,通过get方法,写入action/student/get这个地址
<html>
<head>
<title>查询</title>
</head>
<body style="text-align: center ">
<form action="${pageContext.request.contextPath}/student/get" method = "get">
<input type="text" name="id">
<input type="submit" value="搜索">
</form>
</body>
</html>
那么我们继续在Controller里面建立一个
@RequestMapping(value=“/student/get”,method = RequestMehod=GET)
public String to1(int id ,Model model){
Student student = studentService.selectById(id)
model.AaddAttribute("student",student)
return “get”;
}
查询方法的地址和jsp页面里的一样。程序从id跳转方法开始,然后到jap页面,然后到查询方法地址,然后运行查出来数据,数据存在student里面,它以引号里面的s为名字。
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<th>${student}</th>
<th>${student.id}</th>
<th>${student.name}</th>
<th>${student.qq}</th>
<th>${student.major}</th>
</body>
</html>
通过EL表达式,¥{student}就是引号里面的student,就是个名字,叫啥都行。
运行之后,就输出了数据。也就是从页面输入id,输出其他三项的数据成功了。
二。上面是需要用到数据库,如果不用数据库,直接把后端数据传到前段,该如何处理呢?
首先,建立一个get方法
@Request Mapping(value=“/alibaba/123” @ReQuestMethod=GET)
public String ali(){
String name="哈哈"
model.Add("na",name)
return “go”
}
然后go。jsp页面里
<body>
之间,协商EL表达式,就可以把后端值传到前端来了¥{na}</body>
明天的计划:提交任务二,把前端值如何传到后端也搞明白
遇到的问题:暂无
今天的收获:学会后端值传到前端了,
java任务二开始时间:2018.01.25
预计demo时间:2018.02.12
可能有延期风险,原因是:json看不懂,控制器的逻辑看不懂,所以又回看了java语法
禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html
评论