注解开发关于跳路径页面

年前学了注解式开发,年后再写的时候就有点蒙了,主要是注解那里。现在来复习下。

如果在类上面加注解:

@RequestMapping("/Axx")
@Controller
@RequestMapping("/Student")
public class FindListStuWeb {

方法上加注解:

@RequestMapping("/Bxx")
/**
     * 模糊查
     * @param request
     * @param student
     * @return
     */
    @RequestMapping("/findListStu")
    public String findListStu(HttpServletRequest request, Student student){

那么在页面上点击按钮触发的form表单action里面就是:

${pageContext.request.contextPath}/Axx/Bxx/

如果需要传参就直接在后面传值。

方法里面返回页面:

页面:a.jsp

方法:注意方法里最后return的值必须与jsp页面的命名一致

 public String findListStu(HttpServletRequest request, Student student){
        String sname = student.getSname();
        if(sname == null){
            sname = "";
        }
        System.out.println("------------"+sname);
        student.setSname("%"+sname+"%");
        List<Student> stulist = studentService.FindListStu(student);
        request.getSession().setAttribute("stulist",stulist);
        return "StudentList";//注意这里return的值需与jsp页面的命名一致
    }

前台传参给后台的取值

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
    <script type="text/javascript">
        function add(){
            window.location.href="${pageContext.request.contextPath}/Student/pageUrl?pageUrl=StudentEdit";
        }
        function updateStudent(sid){
            window.location.href = "${pageContext.request.contextPath}/Student/findOneStu/"+sid;
        }
        function deleteStudent(sid){
            window.location.href = "${pageContext.request.contextPath}/Student/deleteStu/"+sid;
        }
    </script>

</head>
<body>
<form action="${pageContext.request.contextPath}/Student/findListStu/" method="post">
    请输入姓名:&nbsp;&nbsp;<input name="sname" type="text"/><input value="查询" type="submit">
</form>
<input value="新增" onclick="add()" type="button">
<table border="1" width="100%">
    <tr style="text-align: center">
        <td>编号</td>
        <td>姓名</td>
        <td>班级</td>
        <td>头像</td>
        <td>操作</td>
    </tr>
    <c:if test="${stulist != null}">
        <c:forEach items="${stulist}" var="stu">
            <tr  style="text-align: center">
            <td>${stu.sid}</td>
            <td>${stu.sname}</td>
            <td>${stu.sclass}</td>
            <td><img src="${stu.image}" width="75px" height="75px"></td>
            <td>
                <button onclick="updateStudent(${stu.sid})">修改</button>
                <button onclick="deleteStudent(${stu.sid})">删除</button>
            </td>
            </tr>
        </c:forEach>
    </c:if>
</table>
</body>
</html>

后台接收并取值

/**
     * 删除
     * @param sid
     * @return
     */
    @RequestMapping("/deleteStu/{sid}")
    public String deleteStu(@PathVariable(value="sid")Integer sid){
        int i = this.studentService.deleteByPrimaryKey(sid);
        return "redirect:/Student/findListStu";
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cy_橘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值