SpringBoot中遇到的一些問題


JQuery和bootstrap報404的問題

在html頁面導入的js和css的時候,不要加static這級目錄,直接跳過即可,例如

 

導入的時候不需要加static目錄,直接導入js/和css/即可

 后台JAVABean的日期類,前台type=date增加報錯的問題

后台錯誤:

Field error in object ‘user‘ on field ‘birthday‘: rejected value [2013-06-24]; codes [typeMismatch.user.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.util.Date‘ for property ‘birthday‘; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value ‘2013-06-24‘; nested exception is java.lang.IllegalArgumentException]

解決辦法

在對應的實體類屬性上加入   @DateTimeFormat(pattern = "yyyy-MM-dd")

前台表單Action訪問后台Controller,后台跳轉html要用重定向

這里直接用return "html地址" 是不行的

  return "redirect:/index"; 

要用重定向。

設置SpringBoot訪問localhost:8080的默認跳轉頁面

 這個在SpringMVC中很好設置直接在Web.xml寫的東西在SpringBoot里面變得有些麻煩

這里要寫一個配置類,在配置類里寫入你想跳轉的默認訪問頁面

代碼如下

@Configuration
    public class DefaultView extends WebMvcConfigurerAdapter {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("forward:/index"); //在這里寫上要跳轉的默認主頁
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
            super.addViewControllers(registry);
        }
    }

 數據源配置錯誤

這里的問題就是我們在創建SpringBoot框架的時候勾選了數據庫相關的依賴,但是在啟動tocmat過程中並沒有配置這個數據庫依賴(比如我勾選了但是沒有用到數據庫,只是測試一下),就會報如下圖的錯誤

解決方法

只能在SpringBootApplication注解中加上下面這行代碼,或者添加數據庫配置

 exclude= {DataSourceAutoConfiguration.class} 

該注解的作用是,排除自動注入數據源的配置(取消數據庫配置),一般使用在客戶端(消費者)服務中

 解決org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)問題

接口Dao的接口名與Mapper的文件名一定要一模一樣。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM