@Controller
public class PortalHandler {
private MySQLRemoteService mySQLRemoteService;
@RequestMapping("/")
public String showPortalPage(Model model){
// 1.呼叫MySQLRemoteService提供的方法查詢首頁要顯示的資料
//debug時下面代碼空指標例外 null,但是單獨測驗mysql部分的代碼是沒有問題的
ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeProjectDataRemote();
// 2.檢查查詢結果
String result = resultEntity.getResult();
if (ResultEntity.SUCCESS.equals(result)){
// 3.獲取查詢資料
List<PortalTypeVO> list = resultEntity.getData();
// 4.存入模型
model.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA,list);
}
return "portal";
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
@FeignClient("atguigu-crowd-mysql")
public interface MySQLRemoteService {
@RequestMapping("/get/portal/type/project/data/remote")
ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote();
}
----------------------------------------------------------------------------------------------------------------------------------------------
@RestController
public class ProjectProviderHandler {
@Autowired
private ProjectService projectService;
@RequestMapping("/get/portal/type/project/data/remote")
public ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote(){
try {
List<PortalTypeVO> portalTypeVOList = projectService.getPortalTypeVO();
return ResultEntity.successWithData(portalTypeVOList);
} catch (Exception e) {
e.printStackTrace();
return ResultEntity.failed(e.getMessage());
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
@Test
public void testLoadTypeDate(){
//測驗時沒有問題
List<PortalTypeVO> typeVOList = projectPOMapper.selectPortalTypeVOList();
for(PortalTypeVO portalTypeVO : typeVOList){
String name = portalTypeVO.getName();
String remark = portalTypeVO.getRemark();
logger.info("name: " + name +" ,remark: " + remark);
List<PortalProjectVO> projectVOList = portalTypeVO.getPortalProjectVOList();
for (PortalProjectVO portalProjectVO : projectVOList){
if (portalProjectVO == null){
continue;
}
logger.info(portalProjectVO.toString());
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/121544.html
標籤:Java相關
上一篇:maven tomcat插件啟動卡在了Starting ProtocolHandler["http-bio-8081"] 沒有警告,也沒有報紅,怎么辦呀
下一篇:Failed to convert value of type 'java.lang.String' to required type 'int[]'
