Mybatis+Thymeleaf開發遇到的幾個問題筆錄

我的開發工具是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;

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