MyBatis小问题(1)-Mapper中错误No constructor found...
前兩天又被公司叫去修改其他產(chǎn)品的一些問(wèn)題了,沒(méi)有看java相關(guān)的,今天周六,看了看MyBatis東西。
就是簡(jiǎn)單的在MySql中建了個(gè)users表,很簡(jiǎn)單,包含id,name,age,寫了個(gè)bean。如下:(注,由于初學(xué)java,可能很多名詞用的并不是特別準(zhǔn)確,大概理解一下就行了,待學(xué)成之后,再行修改。所謂大行不顧細(xì)謹(jǐn),大禮不拘小節(jié),O(∩_∩)O)
package com.tszhao.dao;public class User {private int id;private String name;private int age;public User(int id, String name, int age) {super();this.id = id;this.name = name;this.age = age;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "User [id=" + id + ", name=" + name + ", age=" + age + "]";} }在JUnit中寫了一個(gè)測(cè)試程序,用來(lái)查詢。
@Test public void testSelect() {SqlSessionFactory factory = MyBatisUtils.getFactory();SqlSession openSession = factory.openSession();UserMapper mapper = openSession.getMapper(UserMapper.class);User selectUser = mapper.selectUser(1);System.out.println(selectUser); }結(jié)果,運(yùn)行報(bào)錯(cuò)。。。
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.tszhao.dao.User matching [java.lang.Integer, java.lang.String, java.lang.Integer] ### The error may exist in com/tszhao/mapper/UserMapper.java (best guess) ### The error may involve com.tszhao.mapper.UserMapper.selectUser ### The error occurred while handling results ### SQL: select * from users where id=? ### Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.tszhao.dao.User matching [java.lang.Integer, java.lang.String, java.lang.Integer] at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ...看樣子,應(yīng)該跟構(gòu)造函數(shù)相關(guān)。找不到與User相關(guān)的構(gòu)造函數(shù)。試著在User中增加了一個(gè)默認(rèn)的構(gòu)造函數(shù),通過(guò)。。。
可能問(wèn)題都不值得一提,但是,特此記錄一下學(xué)習(xí)歷程,也是一個(gè)很有意思的事。。。
轉(zhuǎn)載于:https://www.cnblogs.com/zhaoyan001/p/10595773.html
總結(jié)
以上是生活随笔為你收集整理的MyBatis小问题(1)-Mapper中错误No constructor found...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python代码发送post请求接口测试
- 下一篇: LeetCode算法题-Valid Pa