【新手須知】Spring Boot 2.0.0 + MyBatis + Shiro + Swagger 開發項目踩坑記錄

寫在前面

Swagger 2.8.0
Spring Boot 2.0.0.RELEASE
Shiro 1.4.0
Mybatis 1.3.1

填坑

踩坑一:
MyBatis xml文件中參數名選擇
若UserMapper.java寫法爲

User findByUserId(int userId);

則在UserMapper.xml裏參數名只能爲arg0、arg1…

<select id="findByUserId" resultType="com.pojo.User">
        SELECT * FROM user WHERE id=#{arg0}
</select>

想要改成

<select id="findByUserId" resultType="com.pojo.User">
        SELECT * FROM user WHERE id=#{userId}
</select>

則UserMapper.java需要修改爲

User findByUserId(@Param("userId") int userId);

踩坑二:
集成Shiro框架後,重定向導致前端頁面佈局錯亂

    //放行靜態資源
    filterChainDefinitionMap.put("/css/**", "anon");
    filterChainDefinitionMap.put("/js/**", "anon");
    filterChainDefinitionMap.put("/layui/**", "anon");
    filterChainDefinitionMap.put("/pm/login", "anon");

把前端所有靜態資源都免去認證


踩坑三:
集成Shiro + Swagger,Swagger頁面無法查看接口
解決辦法與上面類似

/**
 * @Mark 在線接口文檔路徑
 * @URL http://localhost:8080/swagger-ui.html
 */
 filterChainDefinitionMap.put("/swagger-ui.html","anon");
 filterChainDefinitionMap.put("/static/**", "anon");
 filterChainDefinitionMap.put("/swagger/**","anon");
 filterChainDefinitionMap.put("/webjars/**", "anon");
 filterChainDefinitionMap.put("/swagger-resources/**","anon");
 filterChainDefinitionMap.put("/v2/**","anon");

踩坑四:
分模塊,啓動後報錯:缺失文件
Application主程序添加自動掃包代碼

@ComponentScan(basePackages = {"com.*"})

踩坑五:
動態數據源無法與MyBatis的xml對應起來
具體解決方案見《SpringBoot+MyBatis 動態數據源(含項目地址)》

最後說一個題外話:
就是IEDA在debugger的時候運行特別慢,那有可能是把斷點打在方法上了,改成打在方法內部就好了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章