我是角色的新手,我正在开展一个涉及angular2和Springboot的项目。
我的问题是:
以下是我的角色服务:
import { Component , ViewContainerRef ,ViewEncapsulation} from '@angular/core';
import { OnInit } from '@angular/core' ;
import { ProfileService } from './profile.service' ;
import { Observable } from 'rxjs/Observable';
import { Profile } from './profile';
import {FormsModule} from '@angular/forms' ;
import { Overlay ,overlayConfigFactory } from 'angular2-modal' ;
import { Modal , BSModalContext } from 'angular2-modal/plugins/bootstrap';
import {CustomModalContext , ProfileCreate } from './profile-create.component' ;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [ProfileService , Modal]
})
export class AppComponent implements OnInit{
title = 'Permission Matrix';
constructor(private _profileService : ProfileService , public modal : Modal){}
profiles: Profile[];
ngOnInit(){
console.log("inside component ");
this.getHeroes();
}
getHeroes(): void {
this._profileService
.getProfiles()
.then(prfiles => {
this.profiles = prfiles;
console.log(this.profiles);
});
}
getCreateUpdateScreen(){
return this.modal.open(ProfileCreate, overlayConfigFactory({num1 : 2, num2 : 3 }, BSModalContext));
}
下面是我的角色成分:
export class Profile {
profil_id : string ;
profil_name_lang: string;
profil_name_short: string;
geschaeftsbereich: string;
spezialberatung: string;
}
下面是我在angular中的映射类:
package permissionbackendservice.permissionmatrix.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import permissionbackendservice.permissionmatrix.domain.Profile;
import permissionbackendservice.permissionmatrix.dto.ProfileDto;
import permissionbackendservice.permissionmatrix.service.ProfileService;
@RestController
public class ProfileController {
private final ProfileService profileservice;
@Autowired
ProfileController(ProfileService profileservice) {
this.profileservice = profileservice;
}
@RequestMapping("/profiles")
public List<Profile> readprofiles(){
// This Function will fetch all the profiles in the database
List<Profile> profileList = null ;
try {
profileList = profileservice.readProfiles();
} catch(Exception e) {
e.printStackTrace();
}
return profileList ;
}
// function to delete an existing profiles
@RequestMapping(method = RequestMethod.POST ,value = "/deleteprofile" )
public void deleteProfile(@RequestBody List<Profile> profile){
try {
profileservice.deleteProfile(profile);
} catch(Exception e) {
e.printStackTrace();
}
}
@RequestMapping(method = RequestMethod.POST ,value = "/saveprofile")
public void addProfile(@RequestBody Profile profile){ // this function is for creating new profile
profileservice.addProfile(profile);
}
@RequestMapping(method = RequestMethod.POST ,value = "/updateprofile")
public void updateProfile(@RequestBody Profile profile){ // this function is for updating new profile
profileservice.updateProfile(profile);
}
/*
@RequestMapping(method = RequestMethod.POST, value = "/saveprofile") // function to both add and update profiles in database
public void saveProfile(@RequestParam(value = "profilNameLang") String profileNameLang, @RequestParam(value = "profilNameShort") String profileNameShort , @RequestParam(value = "geschaeftsbereich") String geschaeftsbereich, @RequestParam(value = "profileId") String profileId) {
// In this function control will handled in two ways .If the profileId is null then it means its an addition of new profile as in this case profile id
// will be generated in code and not as an user input ,otherwise if the profile id is not null then its a case of update .
if(profileId == null || profileId.isEmpty()){
profileservice.addProfile(profileNameLang, geschaeftsbereich, profileNameShort);
} else {
profileservice.updateProfile(profileNameLang, geschaeftsbereich, profileNameShort, profileId);
}
}
*/
}
下面是我的弹簧控制器:
<a href="data:application/json; YOUR JSON DATA HERE" download="yourfilename.json">Save</a>