Mybatis系列之前端显示时间格式问题解决方法

举报
yd_273762914 发表于 2020/12/03 01:11:15 2020/12/03
5.5k+ 0 0
【摘要】 我的开发工具是IntelliJ IDEA,然后在SpringBoot集成Mybatis,前端用模块引擎Thymeleaf的过程中遇到几个问题,不过也花了点时间,现在记录下来,作为笔记记录。 Invalid bound statement异常 开发中经常遇到,下面给出我的两种方法 Invalid bound statement (not found): ①Mapepr...

我的开发工具是IntelliJ IDEA,然后在SpringBoot集成Mybatis,前端用模块引擎Thymeleaf的过程中遇到几个问题,不过也花了点时间,现在记录下来,作为笔记记录。

Invalid bound statement异常

开发中经常遇到,下面给出我的两种方法
Invalid bound statement (not found):
①Mapepr.xml文件中文nameapce没有和mapper接口发生映射
②有可能是在IDEA编辑器运行的项目,需要project structure设置mybatis的xml文件夹为resource

Thymeleaf前端显示时间格式不规范

解决方案是写个配置类

package com.muses.taoshop.manager.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistrar;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * <pre>
 * Thymeleaf模板引擎配置
 * </pre>
 *
 * @author nicky
 * @version 1.00.00
 * <pre>
 * 修改记录
 * 修改后版本: 修改人:  修改日期: 2018.09.22 10:50 修改内容:
 * </pre>
 */
@Configuration
public class ThymeleafConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware{ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { } @Override public void addFormatters(final FormatterRegistry registry){ super.addFormatters(registry); registry.addFormatter(dateFormatter()); } @Bean public DateFormatter dateFormatter(){ return new MyDateFormatter(); } class MyDateFormatter extends DateFormatter { @Override public String print(Date date, Locale locale) { //return super.print(date, locale); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); } }
}
  
 

获取后台timestamp类型数据,页面得到一串unix long类型数据

获取后台timestamp类型数据,页面得到一串unix long类型数据,解决方案是用fastjson的@JSONField注解可以解决

 @JSONField(format ="yyyy-MM-dd HH:mm:ss") private Date createTime;
  
 

文章来源: smilenicky.blog.csdn.net,作者:smileNicky,版权归原作者所有,如需转载,请联系作者。

原文链接:smilenicky.blog.csdn.net/article/details/83686014

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。