I am currently trying to build a single page application with springboot, java, and angular js. I had a multi-page application where my java controller handles all the routes. Now that I implemented angular js routes, it is conflicting with my Controller. I need to find a way to rewrite this controller as angular so that my values can be properly displayed on the 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;
}
Angular script
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';
});
My controller above basically takes the value a user inputs and run it through jaxb and unmarshall the rest api based on the value user inputted.
Attempts
1) If I have this controller and my angular js routes running simultaneously, I either not get the partial views or error 404.
2) If I remove my controller, I have my partial views but no values are coming in from sql, or jaxb unmarshalling.
3) Tried switching from ModelAndView to just model (just to render the data on the page). Still giving me error, page cannot load.
Simliar post