一、出现错误:Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'

无法将你的datasource里配置的字符串转换成javax.sql.DataSource对象,导致SessionFactory无法完成,datasource配置肯定有误,检查[/WEB-INF/applicationContext.xml]文件中的datasource相关的配置。
<property name="dataSource" value="dataSource">
配置错了,这写法Spring会以字符串方式注入,报类型不匹配异常,改为
<property name="dataSource" ref="dataSource"/>

二、WEB-INF下的jsp文件一般只能通过请求然后后台controller层才能跳转,直接请求该路径下的文件是进不去的会报404,而如果直接请求文件路径地址,如<a href="${pageContext.request.contextPath }/Novel.jsp/>那么该文件是需要在Webapp文件夹下的。

三、spring mvc绑定参数之类型转换有三种方式:

1.实体类中加日期格式化注解

@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
private Date creationTime;

只是解决了局部问题,解决不了根本问题

2.属性编辑器(一般不用了)

spring3.1之前

在Controller类中通过@InitBinder完成

/**
* 在controller层中加入一段数据绑定代码
* @param webDataBinder
*/
@InitBinder
public void initBinder(WebDataBinder webDataBinder) throws Exception{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
simpleDateFormat.setLenient(false);
webDataBinder.registerCustomEditor(Date.class , new CustomDateEditor(simpleDateFormat , true));
}
备注:自定义类型转换器必须实现PropertyEditor接口或者继承PropertyEditorSupport类
写一个类 extends propertyEditorSupport(implements PropertyEditor){
public void setAsText(String text){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy -MM-dd hh:mm");
Date date = simpleDateFormat.parse(text);
this.setValue(date);
}
public String getAsTest(){
Date date = (Date)this.getValue();
return this.dateFormat.format(date);
}
}

3. 类型转换器Converter(用的比较多,虽然繁琐,但是治本)

 public class DateConvert implements Converter<String, Date> {
private String pattern; public void setPattern(String pattern) {
  this.pattern = pattern;
} @Override
public Date convert(String source) {
  SimpleDateFormat format = new SimpleDateFormat(pattern);
  Date d = null; try {
  d = format.parse(source);
  } catch (ParseException e) {
  e.printStackTrace();
  }   return d;
  }
}

在springMVC.xml中的配置

 <mvc:annotation-driven conversion-service="conversionService"/>
<!-- 自定义的日期转换器-->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="edu.kust.utils.DateConvert">
<!-- 自定义日期格式-->
<property name="pattern" value="yyyy-MM-dd"/>
</bean>
</set>
</property>
</bean>

最新文章

  1. .net 大型分布式电子商务架构说明
  2. file命令
  3. tensorflow学习笔记一:安装调试
  4. Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决方法 + Linux启动/停止/重启Mysql数据库的方法
  5. 关于软件开发中兼容win7注册表的解决方案
  6. MySql相关及如何删除MySql服务
  7. Python3学习
  8. light oj 1214 - Large Division
  9. sentinel监控redis高可用集群(二)
  10. 如何用java实现一个p2p种子搜索(1)-概念
  11. [Abp 源码分析]十四、DTO 自动验证
  12. [工具向]__androidstudio签名打包apk及配置自动签名
  13. linux因勿删或误操作导致登录界面异常,命令无法使用,显示/bin/bash:No such file or directory
  14. centos7.2下nginx安装教程
  15. Android:Error:Execution failed for task &#39;:app:clean&#39;. &gt; Unable to delete directory
  16. Docker中查看Mysql数据库中的各环境参数
  17. PHP URL中包含中文,查看时提示404
  18. Internet History, Technology and Security (Week 4)
  19. 关于Parse字符串为时间一次被坑经历
  20. iOS边练边学--UIScrollView和xib文件实现简单分页+定时器初使用

热门文章

  1. CodeForces-617E XOR And Favorite Numbers(莫队)
  2. (全国多校重现赛一)F-Senior Pan
  3. java之单例设计模式
  4. matlab安装出现“无法访问所在网络位置”的正确解决办法
  5. Python生成器的用法
  6. eclipse配置svn导出项目
  7. getX,getY,getScrollX,getScrollY,ScrollTo(),ScrollBy()辨析
  8. SpringBoot电商项目实战 — 商品的SPU/SKU实现
  9. 面试连环炮系列(二十三): StringBuffer与StringBuild的区别
  10. java8新特性,你有用起来了吗?(精编)