Java之品优购课程讲义_day01(8)
4.1.1 商家管理后臺
構建 web 模塊 pinyougou-shop-web 與運營商管理后臺的構建方式類似。區別:
(1)定義 tomcat 的啟動端口為 9102
(2)springmvc.xml
4.4實體類與數據訪問層模塊
4.4.1生成代碼
利用反向工程 generatorSqlmapCustom 實現實體類與數據訪問層代碼的自動生成
4.4.1 拷貝代碼
將 com.pinyougou.pojo 包拷貝到 pojo 工程
將 com.pinyougou.mapper 包和 resouce 下的 com.pinyougou.mapper 文件夾拷貝到 dao 工程
4.4.2 修改實體類代碼
修改每個實體類,讓其實現 Serializable 接口
5.品牌列表-后端代碼
5.1 需求分析
完成品牌管理的后端代碼,在瀏覽器可查詢品牌的數據(json 格式)
5.2 數據庫表
tb_brand品牌表
品牌首字母
5.1 后端代碼5.2.1 服務層接口在 pinyougou-sellergoods-interface 工程創建 BrandService 接口
package com.pinyougou.sellergoods.service;
import java.util.List;
import com.pinyougou.pojo.TbBrand;
/**
*品牌服務層接口
*@author Administrator
*
*/
public interface BrandService {
/**
*返回全部列表
*@return
*/
public List<TbBrand> findAll();
}
5.2.1 服務實現類
在 pinyougou-sellergoods-service 工程創建 BrandServiceImpl 類
package com.pinyougou.sellergoods.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.pinyougou.mapper.TbBrandMapper;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService; @Service
public class BrandServiceImpl implements BrandService { @Autowired
private TbBrandMapper brandMapper; @Override
public List<TbBrand> findAll() {
return brandMapper.selectByExample(null);
}
}
5.2.1 控制層代碼
在 pinyougou-manager-web 工程創建 com.pinyougou.manager.controller 包, 包下 創建
BrandController 類
package com.pinyougou.manager.controller;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;
/**
- 品牌 controller
- @author Administrator
*/ @RestController
@RequestMapping("/brand")
public class BrandController { @Reference
private BrandService brandService;
/**
*返回全部列表
*@return
*/ @RequestMapping("/findAll")
public List<TbBrand> findAll(){
return brandService.findAll();
}
}
測試
啟動 pinyougou-sellergoods-service
啟動 pinyougou-manager-web
地址欄輸入 http://localhost:9101/brand/findAll.do
可以看到瀏覽器輸出了 json 數據。
附錄:常見錯誤
1.在注冊中心找不到對應的服務
[AppleScript] 純文本查看 復制代碼
?
1
java.lang.IllegalStateException: Failed to check the status of the service com.pinyougou.sellergoods.service.BrandService. No provider available for the service com.pinyougou.sellergoods.service.BrandService from the url zookeeper://192.168.25.129:2181/com.alibaba.dubbo.registry.RegistryService?application=pinyo ugou-manager- web&dubbo=2.8.4&interface=com.pinyougou.sellergoods.service.BrandService&methods=updat e,get,delete,selectOptionList,add,getListByPage&pid=3980&revision=0.0.1- SNAPSHOT&side=consumer×tamp=1501146823396 to the consumer 172.16.17.14 use dubbo version 2.8.4
這種錯誤是服務層代碼沒有成功注冊到注冊中心導致,請檢查一下你的服務層代碼是否添加了@service 注解,并且該注解的包一定是 com.alibaba.dubbo.config.annotation 包,不是
org.springframework.stereotype.Service,這個地方極容易出錯。另外還有一個原因就是你的 服務層工程由于某些原因沒有正常啟動,也無法注冊到注冊中心里。
無法連接到注冊中心
請檢查 IP 與端口是否填寫正確,檢查注冊中心是否正常啟動
轉載于:https://blog.51cto.com/13517854/2150529
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Java之品优购课程讲义_day01(8)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unexpected end of JS
- 下一篇: Navicatfor mysql怎么设置