1.網(wǎng)上搜了半天都是說什么原因造成的?
就是你查找的兩張表有重復(fù)字段,SQL語句在查找的時候不知道你的字段是取的哪張表里的,就會報未明確定義列。
select * from table a inner join table b on a.id=b.id where id='3';
這里,他就不知道你的id字段是取的table a表,還是table b表,解決就是在id上添加a或b,看你去哪張表中取字段。
select * from table a inner join table b on a.id=b.id where a.id='3';
2.Mybatis-plus代碼中可直接修改:
但是在mybatis-plus中,我們?nèi)∽侄味际?/p>
QueryWrapper querywrapper=new QueryWrapper();
querywrapper.eq("id","3");
要解決這個問題只需要:querywrapper.eq("a.id","3")
執(zhí)行看一下是不是和這個語句“select * from table a inner join table b on a.id=b.id where a.id='3'”完全一樣。
不要動不動就修改數(shù)據(jù)庫字段,數(shù)據(jù)庫字段是能隨便改的嗎?
3.mybatis-plus中dao層分頁sql
@Select("select? a.*,b.id? "? +
? ? ? ? ? ? ? ?" from table a "? +
? ? ? ? ? ? ? ?" inner join table b "? +
? ? ? ? ? ? ? ?" on a.id=b.id "? +
? ? ? ? ? ? ? ? "${ew.customSqlSegment}? ")
IPage<實體類> selectpage (
? ? ? ? Ipage<實體類> page,
@Param(Constants.WRAPPER)QueryWrapper<實體類>querywrapper)
注意:sql語句一定要注意空格,不然,就可能出現(xiàn)【 b.idfrom】,導(dǎo)致sql語句錯誤。