Home > Back-end >  Spring Cloud remote call interface, the null pointer exception really solve
Spring Cloud remote call interface, the null pointer exception really solve

Time:09-25

@ Controller
Public class PortalHandler {

Private MySQLRemoteService MySQLRemoteService;

@ RequestMapping ("/")
Public String showPortalPage Model (Model) {

//1. The way to call MySQLRemoteService provides query page to display the data
//debug code under the null pointer exception null, but separate test mysql part of the code is no problem of
ResultEntity ResultEntity=mySQLRemoteService. GetPortalTypeProjectDataRemote ();

//2. Check the query results
The String result=resultEntity. GetResult ();
If (ResultEntity. SUCCESS. Equals (result)) {

//3. Obtain the query data
List List=resultEntity. GetData ();

//4. Deposit model
Model. The addAttribute (CrowdConstant ATTR_NAME_PORTAL_DATA, a list).
}
Return "portal";
}

}


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

@ FeignClient (" atguigu - the crowd - mysql ")
Public interface MySQLRemoteService {

@ RequestMapping ("/get/portal/type/project/data/remote ")
ResultEntity GetPortalTypeProjectDataRemote ();
}



-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@ RestController
Public class ProjectProviderHandler {

The @autowired
Private ProjectService ProjectService;

@ RequestMapping ("/get/portal/type/project/data/remote ")
Public ResultEntity GetPortalTypeProjectDataRemote () {
Try {
List PortalTypeVOList=projectService. GetPortalTypeVO ();
Return ResultEntity. SuccessWithData (portalTypeVOList);
} the catch (Exception e) {
e.printStackTrace();
Return ResultEntity. Failed (um participant etMessage ());
}
}
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@ Test
Public void testLoadTypeDate () {
//test no problem
List TypeVOList=projectPOMapper. SelectPortalTypeVOList ();
For (PortalTypeVO PortalTypeVO: typeVOList) {
String name=portalTypeVO. GetName ();
String remark=portalTypeVO. GetRemark ();
Logger. The info (" name: "+ name +", remark: "+ remark);

List ProjectVOList=portalTypeVO. GetPortalProjectVOList ();
For (PortalProjectVO PortalProjectVO: projectVOList) {
If (portalProjectVO==null) {
continue;
}
Logger. The info (portalProjectVO. ToString ());
}

}

}
  • Related