我使用过myBatis,在应用启动期间出现错误:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for pl.net.manager.dao.ProductDAO.getService()
### The error may exist in pl/net/manager/dao/ProductDAO.java (best guess)
### The error may involve pl.net.manager.dao.ProductDAO.getProduct
### The error occurred while handling results
### SQL: select * from product where id=?
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for pl.net.manager.dao.ProductDAO.getService()
我有以下表格:产品,服务,费率计划
我有三个DAO&#39>:
ProductDao这个:
@Mapper
public interface ProductDAO extends ServiceDAO, RateplanDAO {
@Select("select * from product")
@Results({
@Result(property = "id", column = "id"),
@Result(property = "productStatus", column = "product_status"),
@Result(property = "createdBy", column = "created_by"),
@Result(property = "createdDate", column = "created_date"),
@Result(property = "modifiedBy", column = "modified_by"),
@Result(property = "modifiedDate", column = "modified_date"),
@Result(property = "service", column = "service", one = @One(select = "getService()")),
@Result(property = "rateplan", column = "rateplan", one = @One(select = "getRateplan()"))
})
public List<Product> getProductList();
@Select("select * from product where id=#{id}")
@Results({
@Result(property = "id", column = "id"),
@Result(property = "productStatus", column = "product_status"),
@Result(property = "createdBy", column = "created_by"),
@Result(property = "createdDate", column = "created_date"),
@Result(property = "modifiedBy", column = "modified_by"),
@Result(property = "modifiedDate", column = "modified_date"),
@Result(property = "service", column = "service", one = @One(select = "getService()")),
@Result(property = "rateplan", column = "rateplan", one = @One(select = "getRateplan()"))
})
public Product getProduct(Integer id);
ServiceDAO:
@Mapper
public interface ServiceDAO {
@Select("select * from service where id=#{id}")
@Results({
@Result(property = "id", column = "id"),
@Result(property = "serviceStatus", column = "service_status"),
@Result(property = "name", column = "name"),
@Result(property = "createdBy", column = "created_by"),
@Result(property = "createdDate", column = "created_date"),
@Result(property = "modifiedBy", column = "modified_by"),
@Result(property = "modifiedDate", column = "modified_date")
})
public Service getService(Integer id);
RateplanDAO:
@Mapper
public interface RateplanDAO {
@Select("select * from rateplan where id=#{id}")
@Results({
@Result(property = "id", column = "id"),
@Result(property = "name", column = "name"),
@Result(property = "rateplanStatus", column = "rateplan_status"),
@Result(property = "createdBy", column = "created_by"),
@Result(property = "createdDate", column = "created_date"),
@Result(property = "modifiedBy", column = "modified_by"),
@Result(property = "modifiedDate", column = "modified_date")
})
public Rateplan getRateplan(Integer id);
我已经为产品编写了简单的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MainApplication.class)
@SpringBootTest
public class ProductDaoTest {
@Autowired
ProductDAO productDAO;
@Test
public void getAllProductsTest(){
List<Product> list = productDAO.getProductList();
assertNotNull(list);
assertEquals(2, list.size());
}
@Test
public void getSpecifiedProductTest(){
Integer id =1;
Product product = productDAO.getProduct(id);
assertEquals(id, product.getId());
}
}
如果我理解正确的问题是映射,但根据文档它应该一直在工作。你有一个想法,它是如何解决的?
答案 0 :(得分:1)
您需要在@Result
中删除方法名后的括号:
@Result(property = "service", column = "service", one = @One(select = "getService()"))
=&GT;
@Result(property = "service", column = "service", one = @One(select = "getService"))