AngularJS中 带参数的页面跳转

项目是ssm+angularJS。其中一个模块设计到页面的跳转并携带参数。如下图所示id=1,点击查看按钮跳转实现查看id=1的同学详情。
在这里插入图片描述
查看资料网络普遍采用ui-router,我配置了几次没有成功。尝试了另外的方法。特此记录。

  1. 首先在当前页的html中给button设置一个事件,并获取将要传递的id。
<button type="button" class="btn bg-olive btn-xs"   ng-click="toDetails(sid=entity.id)" >查看</button>
  1. 当前页的JS 的controller层:传递参数并跳转页面
app.controller('studentController',function($scope,$http){
			$scope.toDetails=function (sid) {
				var hre = '4-studentDetails.html?id=' +sid; //跳转页
				location.href = hre;
			};
	});
  1. 跳转页。在跳转页首先接受整个地址,并分割参数id。然后向controller层带上参数发起请求。
app.controller('stuController',function($location,$scope,$http){
   		//接收参数
   		$scope.viewStudent=function(){
   			var urlValue='';
   			var href = location.href; 
   			urlValue = href.substr(href.indexOf("=") + 1);
   			message=angular.fromJson(decodeURI(urlValue));

   			//向后端controller层发起请求
   			$http.get('../student/viewDetails.do?id='+message).success(
   					function(response){
   						$scope.list=response;
   					}
   			);
   		};
   	});
  1. 后端:接受请求并返回json给前端
   @ResponseBody
   @RequestMapping("/viewDetails")
   public List<Student> learnDetails(Student student){
       List<Student> stuList = studentService.queryStuById(student.getId());
       return stuList;
   }

参考文献:
[1]:https://blog.csdn.net/xuehu837769474/article/details/80445417#commentBox


觉得有用,点个赞再走吧~

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值