如何从弹簧控制器获取值到 Angular js

古瓦利乌尔

如何在 angular js 页面中获取此值以在 JSP 页面中显示详细信息。请帮助获取此值并使用 Ajax 调用在 Angular JS 中查看它。

@Controller

public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;
    @RequestMapping(value = "/iwill", method = RequestMethod.GET)
    public ModelAndView searchd() {


        return new ModelAndView("search");
    }


     @RequestMapping(value = "/search", method = RequestMethod.GET)
     public @ResponseBody void  search(HttpServletResponse res,HttpServletRequest req) throws IOException {

     List<Employee> data =  employeeService.listEmployeess();
       JSONArray array = new JSONArray();
           for (Employee e : data) {
               JSONObject jsonObject = new JSONObject(e);
               array.put(jsonObject);
           }
        res.getWriter().append(array.toString());

       }
    }

我的 Angular js 页面:

在这里,我不知道如何获取我的数据。如果我只是 ( http://localhost:8080/sdnext/search.html ) 使用此 url 显示 json 数据,如果我在 angular js 中实现它不会抛出错误但没有显示数据.

  <!doctype html>
<html >
    <head>
        <title>Spring MVC + AngularJS Demo</title>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
        <script>
        function Hello($scope, $http) {
            $http.get('http://localhost:8080/sdnext/search.html').
                success(function(response) {
                    $scope.employees = response.data;
                });
        }
        </script>
    </head>
    <body ng-app="app">

        <table>
        <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Age</th>
        <th>salary</th>
        <th>Address</th>
        <th>BloodGrp</th>
        <th>Aids</th>
        <th>Weight</th>
        </tr>
        <tr>

<tbody  ng-controller="Hello">
 <tr ng-repeat="employee in employees"> 
 <td>{{employee.empId}}</td>
  <td>{{employee.empName}}</td>
   <td>{{employee.empAge}}</td> 
   <td>{{employee.salary}}</td> 
   <td>{{employee.empAddress}}</td>
    <td>{{employee.bloodgrp}}</td> 
    <td>{{employee.aids}}</td>
     <td>{{employee.weight}}</td> 
     </tr> </tbody> 
            </table>

    </body>
</html>

**

我在下面给出了我的 JSON 响应:这是我在使用 url http://localhost:8080/sdnext/search.html 时得到的,但我不知道如何在 Angular js 中使用它在 jsp 页面中显示我的数据。

**

[{"empId":1,"bloodgrp":"0-ve","empName":"krishnaKumars","weight":78,"aids":"negative","empAge":23,"salary":15000,"empAddress":"madurai"},{"empId":2,"bloodgrp":"o-ve","empName":"Archanasundar","weight":68,"aids":"Negative","empAge":31,"salary":50000,"empAddress":"chennai"},{"empId":4,"bloodgrp":"o-ve","empName":"Kabali","weight":78,"aids":"negative","empAge":23,"salary":201300,"empAddress":"Madurai"}]
帕诺斯K

您需要从“/search”处的 angular $http.get 发出 ajax 请求

这行得通

@RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)

     public List<Employee> search( ) throws IOException {

     return  employeeService.listEmployeess();

       }

你弄错了

function Hello($scope, $http) {
            $http.get('http://localhost:8080/sdnext/search.html').
                success(function(response) {
                    $scope.employees = pesponse;
                });
        }

$scope.employees = response.data 是正确的

应该是这样的

<script>
angular.module("app",[])
        .controller("Hello",function ($scope,$http){
     $scope.getData = function() {
            $http.get('http://localhost:8080/sdnext/search.html').
                success(function(response) {
                    $scope.employees = response.data;
                });
        }
    });

        </script>

<tbody  ng-controller="Hello" ng-init="getData ()">

检查这些告诉我是否有效

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从弹簧控制器获取数据到角度js

Angular JS 没有从 HTML 到控制器获取范围值

在Angular JS中从模型到控制器检索id

如何将JSON数据从C#控制器传递到angular js?

如何在Angular JS中将数据从工厂传递到控制器?

Angular.js:在控制器中获取元素

如何在Angular JS中获取到控制器的路由值

如何在angular js控制器中使用alasql?

如何在Angular.js中访问控制器

如何从promise方法内部访问angular js控制器的“ this”?

如何从Angular JS中的控制器更改视图?

如何在Angular JS的子控制器中访问父控制器数据

Angular.js-装饰控制器

实例化angular js控制器

Angular js控制器多次注入

Angular JS部分控制器

Angular JS无法识别控制器

Angular JS:如何在Angular指令中从控制器的链接内部调用函数

从控制器导航到angular js中的其他页面

哪些参数要传递到Angular JS自定义指令控制器中?

Angular.js将错误消息从服务传递到控制器$ scope

angular js,将数据作为参数从视图传递到控制器

将Browserify与Angular JS一起使用--将服务传递到控制器

angular js:无法将值从控制器传递到包含页面的html

Angular.js:将日历值从指令传递到控制器

从 angular js 中的控制器获取 html 中的数组键值?

无法使用 Angular.js 在控制器中获取模式弹出值

从我的控制器在angular.js中将图像获取到我的html

从模型获取数据到控制器(Ember.js)