1 java model-view-controller controller angularjs
这是我的情况,我在Netbeans 8.2中有一个项目,在html中,这里调用angularjs,但是当需要从angular调用java控制器时我们在chrome调试中收到"not found",在工厂用$ http发送"url",但我不能调用java控制器.
- 这是代码html
<div data-ng-app="myApp">
<div data-ng-controller="MyController">
<button data-ng-click="getDataFromServer()">Test Angularjs</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
- 这是angularjs中的代码(这是一个File.js)
var app = angular
.module('myApp', ['ngRoute', 'ngResource'])
.controller('MyController', function ($scope, $service, $http, $resource) {
$scope.getDataFromServer = function () {
$service.JS_STST_GetData();
}
})// end controller
.factory(
'$service',
function ($http) {
return {
JS_STST_GetData: function (){
$http({
method: 'POST',
url: 'TestMaping',
headers: {
'Content-Type': 'application/json'
}
}).then(_success, _error);
},
Run Code Online (Sandbox Code Playgroud)
- 这是Java控制器代码
@Controller
public class VerController {
@RequestMapping(value="/TestMaping", method = RequestMethod.POST)
public String TEST(Model model){
return "Test";
}
@RequestMapping(method = RequestMethod.GET)
public String otroMetodo(Model model){
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1027 次 |
| 最近记录: |