Groovy文件的未知语法错误

时间:2023-01-28 09:15:54

I'm working on a site with CRUD capabilities for a school project. We're using angular, JSON groovy and MySql for the project. I'm using this code in an HTML file:

我正在为一个学校项目开发具有CRUD功能的网站。我们正在为项目使用angular,JSON groovy和MySql。我在HTML文件中使用此代码:

$scope.getUsers=function(){

    $scope.employees=$http.get('getUsers.groovy').success(function(response){
        return response.data
    }

When I run the html page and call the getUser function, I get this error:

当我运行html页面并调用getUser函数时,我收到此错误:

syntax error getUsers.groovy:1

语法错误getUsers.groovy:1

The code in the groovy file seems correct:

groovy文件中的代码似乎是正确的:

 import groovy.sql.Sql
 import flexjson.JSONSerializer;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import java.sql.SQLException;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 System.out.println("Arrived users");
  JSONSerializer serializer = new JSONSerializer();
  response.setHeader("Access-Control-Allow-Origin", "*");
 sql = Sql.newInstance("jdbc:mysql://localhost:8080/test", "root","", "com.mysql.jdbc.Driver")
 def query="select c.id,c.Name, c.Address, c.Department  from people c order by c.id";
  JSONArray json = new JSONArray();
  sql.eachRow(query) {row->
   JSONObject obj = new JSONObject();
    obj.put("id",row.id);
   obj.put("name",row.Name);
    obj.put("address",row.Address);
    obj.put("dept",row.Department);
    json.put(obj);
   }
       out<< json;

Any help would be greatly appreciated!! It's for my final project

任何帮助将不胜感激!!这是我最后的项目

1 个解决方案

#1


getUsers.groovy is not a http URL. Your groovy implementation should map to a web service that returns JSON response. So this $http.get('getUsers.groovy') should be more like $http.get('http://yourserver/users').

getUsers.groovy不是http URL。您的groovy实现应该映射到返回JSON响应的Web服务。所以这个$ http.get('getUsers.groovy')应该更像$ http.get('http:// yourserver / users')。

On a more general note, anularjs is a client-side technology while groovy is server-side. Checkout this tutorial for better understanding.

更一般地说,anularjs是客户端技术,而groovy是服务器端。查看本教程以便更好地理解。

#1


getUsers.groovy is not a http URL. Your groovy implementation should map to a web service that returns JSON response. So this $http.get('getUsers.groovy') should be more like $http.get('http://yourserver/users').

getUsers.groovy不是http URL。您的groovy实现应该映射到返回JSON响应的Web服务。所以这个$ http.get('getUsers.groovy')应该更像$ http.get('http:// yourserver / users')。

On a more general note, anularjs is a client-side technology while groovy is server-side. Checkout this tutorial for better understanding.

更一般地说,anularjs是客户端技术,而groovy是服务器端。查看本教程以便更好地理解。