随笔 for the first time

随笔 for the first time

SSM

ssm:SpringMVC+Spring+MyBatis

redirect

redirect重定向,在本类的不同方法中跳转。
forward转发,不用类中不同方法的跳转

//跳转到的是jsp页面,".do"是配置的后缀,可改
 public class RedirectController{
    @RequestMapping("list.do")
    public String list(){ 
          return "list";
    }
   //重定向
   @RequestMaooing("add.do")
   public String add(){
     return "redirect:list.do"
   }
}
public class forWordController{
 //转发
  @RequestMapping("look.do")
  public String look{
    return "forward:add.do";
  }
}

@RequestParam与Model

@RequestParam可以使得前端命名的name和后端接收的name不同名。
model可以把参数存储在里面并传到前端的jsp页面,在jsp页面用${name}获取到传递的name值。

<form action="add.do">
     <input type="text" name="username">
</form>
@RequestMapping("add.do")
public String add(@RequestParam("username") String name,Model model){
    model.addAttribute("name",name);
    return "add";
}

存储一些student数据在List,并传递到前端。<:c >标签引用到的是<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>用的话需要加入依赖。

public class StudentController{ 
   private List<Student> students=new ArrayList<Student>();
   @RequestMapping("add.do")
   public String add(Student student){
   //每次增加学生的时候,students增加一个学生
     students.add(student);
     return "redirect:list.do";
 }
   @RequestMapping("list.do")
   public String list(Model model){
     model.addAttribute("students",students);
     return "liststudents";
  }
}
<table>
<thread>
   <tr>
      <td>name</td>
      <td>password</td>
   </tr>
</thread>
<tbody>
   <c:forEach items="${students}" var="student">
      <tr>
         <td>${student.name}</td>
         <td>${student.password}</td>
      </tr>
</tbody>
</table>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值