日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
springboot整合mybatis中的問(wèn)題及出現(xiàn)的一些問(wèn)題小結(jié)

1.springboot整合mybatis mapper注入時(shí)顯示could not autowire,如果強(qiáng)行寫(xiě)(value  = false ),可能會(huì)報(bào)NullPointException異常

超過(guò)十余年行業(yè)經(jīng)驗(yàn),技術(shù)領(lǐng)先,服務(wù)至上的經(jīng)營(yíng)模式,全靠網(wǎng)絡(luò)和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務(wù)范圍包括了:網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作,成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡(luò)托管,重慶小程序開(kāi)發(fā)公司,微信開(kāi)發(fā),app軟件開(kāi)發(fā),同時(shí)也可以讓客戶的網(wǎng)站和網(wǎng)絡(luò)營(yíng)銷(xiāo)和我們一樣獲得訂單和生意!

解決方案:

dao層加注解@Component(value = "首字母小寫(xiě)的接口名如UserMapper->userMapper")

dao層還可以加注解@Mapper

2.The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone問(wèn)題

springboot整合mybatis中的問(wèn)題及出現(xiàn)的一些問(wèn)題小結(jié)

3.java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type[xxx]

解決:實(shí)體對(duì)象類(lèi)沒(méi)有序列化,需要implements Serializable

PS:下面看下springboot整合mybatis出現(xiàn)的一些問(wèn)題

springboot整合mybatis非常非常的簡(jiǎn)單,簡(jiǎn)直簡(jiǎn)單到發(fā)指。但是也有一些坑,這里我會(huì)詳細(xì)的指出會(huì)遇到什么問(wèn)題,并且這些配置的作用

整合mybatis,無(wú)疑需要mapper文件,實(shí)體類(lèi),dao層,數(shù)據(jù)庫(kù)連接池。。。。。也就沒(méi)了。

先放配置application.yml

spring:
 datasource:
  type: com.alibaba.druid.pool.DruidDataSource
  driver-class-name: com.MySQL.jdbc.Driver
  filters: stat
  maxActive: 20
  initialSize: 1
  maxWait: 60000
  minIdle: 1
  timeBetweenEvictionRunsMillis: 60000
  minEvictableIdleTimeMillis: 300000
  validationQuery: select 'x'
  testWhileIdle: true
  testOnBorrow: false
  testOnReturn: false
  poolPreparedStatements: true
  maxOpenPreparedStatements: 20
  
  name: test
  url: jdbc:mysql://localhost:3306/mama-bike?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
  username: root
  password: root

mybatis:
 #告訴spring你的mapper的位置。
 mapper-locations: classpath:com/coder520/mamabike/**/**.xml
 #告訴spring你的實(shí)體類(lèi)的位置
 type-aliases-package: classpath:com.coder520.mamabike.**.entity

logging:
 config: classpath:logback.xml

dao層接口      //就簡(jiǎn)單的寫(xiě)一個(gè)方法

public interface UserMapper {
 int insert(User record);
}

mapper

<?xml version="1.0" encoding="UTF-8" ?>


 
 
 
 
 
 
 
 
 
 id, nickname, enable_flag, verify_flag, head_img, mobile
 
 
 insert into user (id, nickname, enable_flag, 
  verify_flag, head_img, mobile
  )
 values (#{id,jdbcType=BIGINT}, #{nickname,jdbcType=VARCHAR}, #{enableFlag,jdbcType=TINYINT}, 
  #{verifyFlag,jdbcType=TINYINT}, #{headImg,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}
  )
 

main方法

@SpringBootApplication
@ComponentScan(basePackages={"com.coder520.mamabike"})
@MapperScan(basePackages="com.demo.user.mapper")
public class MamaBikeApplication {
 public static void main(String[] args) {
  SpringApplication.run(MamaBikeApplication.class, args);
 }
}

需要注意的是,dao層接口spring怎么會(huì)知道呢?這里就需要@MapperScan(basePackages="com.demo.user.mapper") 這個(gè)注解來(lái)指定mapper接口的位置。用@ComponentScan(basePackages={"com.coder520.mamabike"})這個(gè)注解來(lái)讓spring掃描我們指定包下的注解。

如果我們不用@MapperScan這個(gè)注解的話,也可以在接口類(lèi)的上方加上@Mapper這個(gè)注解也可以。

總結(jié)

以上所述是小編給大家介紹的springboot整合mybatis中的問(wèn)題及出現(xiàn)的一些問(wèn)題小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!


網(wǎng)站標(biāo)題:springboot整合mybatis中的問(wèn)題及出現(xiàn)的一些問(wèn)題小結(jié)
URL標(biāo)題:http://www.dlmjj.cn/article/gjiodj.html