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的文件名一定要一模一样。

 

 

posted @ 2019-05-13 11:03  小王同学!  阅读(6598)  评论(0编辑  收藏  举报