【发布时间】:2017-03-08 20:19:15
【问题描述】:
我目前正在尝试使用 springboot、java 和 angular js 构建单页应用程序。我有一个多页应用程序,其中我的 java 控制器处理所有路由。现在我实现了 Angular js 路由,它与我的控制器发生冲突。我需要找到一种方法将此控制器重写为 angular,以便我的值可以正确显示在 UI 上。
@Controller
public class IndexController {
@Autowired
JAXSample index;
@Autowired
VD_Repo vdRepo;
@Autowired
PD_Repo pdRepo;
@Autowired
CH_Repo chRepo;
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView index(Locale locale) throws MalformedURLException {
ModelAndView model = new ModelAndView("index");
return model;
}
@RequestMapping(value = "/getValues", method = RequestMethod.GET)
public ModelAndView getvalues(Info info) throws MalformedURLException {
ModelAndView model = new ModelAndView("getvalues");
model.addObject("Haddress", info.getHouseAddress());
dCert custinfo = index.readXML(info.getHouseAddress());
model.addObject("custinfo", custinfo);
model.addObject("checked", true);
model.addObject("ch", chRepo.getAll(info.getHouseAddress()));
model.addObject("pd", pdRepo.getAll(info.getHouseAddress()));
model.addObject("vd", vdRepo.getAll(info.getHouseAddress()));
return model;
}
角度脚本
var App = angular.module('App', ['ngRoute']);
App.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
.when('/getValues', {
templateUrl : 'pages/getValues.html',
controller : 'detailsController'
});
});
App.controller('mainController', function($scope) {
$scope.message = 'This is Home page';
});
App.controller('valuesController', function($scope) {
$scope.message = 'This is Values';
});
我上面的控制器基本上采用用户输入的值并通过 jaxb 运行它,并根据用户输入的值解组其余 api。
尝试
1) 如果我有这个控制器和我的 Angular js 路由同时运行,我要么没有得到部分视图,要么出现错误 404。
2) 如果我删除我的控制器,我有我的部分视图,但没有值来自 sql 或 jaxb 解组。
3) 尝试从 ModelAndView 切换到仅模型(仅在页面上呈现数据)。仍然给我错误,页面无法加载。
类似post
【问题讨论】:
标签: javascript java angularjs spring-boot jaxb