yangaijun / multipleselect Goto Github PK
View Code? Open in Web Editor NEWjava 结合mybatis-plus 实现非手写sql多表查询
java 结合mybatis-plus 实现非手写sql多表查询
namespace in MultipleMapper.xml should be namespace="com.freedomen.multipleselect.mapper.MultipleMapper"
MultipleSelect.setPage(pageNo, pageSize, Boolean searchCount);
当searchCount为false时,不查询总条数,返回total=0
required a bean of type 'com.freedomen.multipleselect.service.MultipleService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
// user 表
@TableId
private Integer userId
// address 表
@TableId
private Integer addressId
@TableField(value = "address_user_id")
private Integer userId
你说导入包到项目中,但是你的包怎么查不到呀?
multipleSelect.where("${1}")
.division()
.eq("userName", "张三")
.eq("userPhone", "123")
.or()
.division()
.eq("userName", "李四")
.eq("userPhone", "456");
sql: WHERE ( user_name = "张三" AND user_phone = "123" ) OR ( OR user_name = "李四" OR user_phone = "456" )
两个问题:
1.OR ( OR user_name = "李四"
多个括号的时候,第二个括号开始会多出来一个OR
我把WhereCustomSegment.java 中的第42行
if (segmentSql.get(segmentSql.size() - 1).indexOf("(") == -1
|| (segmentSql.get(segmentSql.size() - 1).indexOf("(") != -1 && segmentSql.get(segmentSql.size() - 1).indexOf(")") != -1))
改成if (segmentSql.get(segmentSql.size() - 1).indexOf("(") == -1)就好了
2.user_name = "李四" OR user_phone = "456"
这里我实际想要的是user_name = "李四" AND user_phone = "456"
发现
.or()
.division()
.eq("userName", "李四")
.and()
.eq("userPhone", "456");
可以达到预期效果,但感觉怪怪的
另外,条件构造器可以再完善下吗,比如isNull、groupBy、having
1.有没有只查询总记录的入口
2.设置参数
-2.1 根据字段去重如:
count(distinct hs_id)
-2.2 目前有没有别的方法来设置字段,活用的那种
MultipleSelect m2 = MultipleSelect.newInstance("${1}.hsId",
new Abb(), new Bcc());
m2.setColumns("abb.hs_Id");
这种方法设置参数都是写死的 abb.hs_id
能否提供一种便捷的参数类型设置类似${1}.hsId
Please☺
多表连接连接字段自己定义
`select distinct meuproductcategory.serial_version_u_i_d serialVersionUID,meuproductcategory.id id,meuproductcategory.id parentId,meuproductcategory.name name,meuproductcategory.level level,meuproductcategory.product_count productCount,meuproductcategory.product_unit productUnit,meuproductcategory.nav_status navStatus,meuproductcategory.show_status showStatus,meuproductcategory.sort sort,meuproductcategory.icon icon,meuproductcategory.keywords keywords,meuproductcategory.description description,meuproductcategory.serial_version_u_i_d serialVersionUID,meuproductcategory.id id,meuproductcategory.id parentId,meuproductcategory.name name,meuproductcategory.level level,meuproductcategory.product_count productCount,meuproductcategory.product_unit productUnit,meuproductcategory.nav_status navStatus,meuproductcategory.show_status showStatus,meuproductcategory.sort sort,meuproductcategory.icon icon,meuproductcategory.keywords keywords,meuproductcategory.description description from meu_product_category as meuproductcategory left join meu_product_category as meuproductcategory on meuproductcategory.id = meuproductcategory.id
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Not unique table/alias: 'meuproductcategory'
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:93) ~[spring-jdbc-5.2.1.RELEASE.jar:5.2.1.RELEASE]`
想要查询的是这中的是不是不行啊
select * from meu_product_category as c1 left join meu_product_category as c2 on c1.id = c2.parent_id
// user 表
@TableId(value = "id")
private Integer userId
// address 表
@TableId(value = "id")
private Integer addressId
private Integer userId
测试结果:user.user_id、address.address_id
正确结果应该是user.id、address.id
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.