Closed yangyang0507 closed 5 years ago
为什么wrapper里没有sqlsegment属性,却可以 ${ew.sqlSegment}调用
关联属性的增删改查怎么简单的实现,不想去写mapper.xml希望通过注解的方式来实现
当初学TP的时候就想着JAVA什么时候能有这种简易操作数据库的方法,这不AR来了,赞
EntityWrapper
@hb39589961 EntityWrapper
ew = new EntityWrapper (); 没有EntityWrapper,在jar包中也没有找到,需要自己实现Wrapper吗
应该是你的包导入不正确
@529435389
@hb39589961 EntityWrapper
ew = new EntityWrapper (); 没有EntityWrapper,在jar包中也没有找到,需要自己实现Wrapper吗 应该是你的包导入不正确 这是我的导包:求帮忙看看错在哪里了 ext { springBootVersion = '2.0.3.RELEASE' mybatisPlusVersion = "3.0-gamma" }
testCompile group: 'junit', name: 'junit', version: '4.12' compile('org.springframework.boot:spring-boot-starter-jdbc') compile('org.springframework.boot:spring-boot-starter-mail') //compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-websocket') //compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2') runtime('mysql:mysql-connector-java') //compileOnly('org.projectlombok:lombok') //使用后报错,疑似版本问题,该包的引用在common中 testCompile('org.springframework.boot:spring-boot-starter-test')
//使用mybatis plus,需要去掉原来的mybatis包
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-undertow:${springBootVersion}")
//compile("com.h2database:h2:1.4.197")
//compile("com.zaxxer:HikariCP:3.2.0")
compile("com.baomidou:mybatis-plus-boot-starter:${mybatisPlusVersion}")
compileOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
我是maven,你的gradle我玩不起来啊
@529435389 这里有 demo https://gitee.com/baomidou/mybatisplus-spring-boot
就是照着这个版本做的
@JamesZBL @529435389 这里有 demo https://gitee.com/baomidou/mybatisplus-spring-boot
感谢!
貌似是改成了QueryWrapper
有一个问题:数据库里字段的名称是AaBb形式,那使用代码生成器时,实体类属性名称就会时AaBb形式,我想知道除了修改数据库字段名称外,可否在生成实体类时自己定义配置下?
使用拼接的方式,支持多表联查吗?
请问复合主键要怎么配置?
// Jackson 方式
objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
这个配置加在哪里?
3.x版本没有Pagination包引用?
求教:多租户怎么利用cookie注入tenandId字段
@hb39589961
@529435389
@hb39589961 EntityWrapper
ew = new EntityWrapper (); 没有EntityWrapper,在jar包中也没有找到,需要自己实现Wrapper吗 应该是你的包导入不正确 这是我的导包:求帮忙看看错在哪里了 ext { springBootVersion = '2.0.3.RELEASE' mybatisPlusVersion = "3.0-gamma" }
testCompile group: 'junit', name: 'junit', version: '4.12' compile('org.springframework.boot:spring-boot-starter-jdbc') compile('org.springframework.boot:spring-boot-starter-mail') //compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-websocket') //compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2') runtime('mysql:mysql-connector-java') //compileOnly('org.projectlombok:lombok') //使用后报错,疑似版本问题,该包的引用在common中 testCompile('org.springframework.boot:spring-boot-starter-test')
//使用mybatis plus,需要去掉原来的mybatis包 compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") compile("org.springframework.boot:spring-boot-starter-undertow:${springBootVersion}") //compile("com.h2database:h2:1.4.197") //compile("com.zaxxer:HikariCP:3.2.0") compile("com.baomidou:mybatis-plus-boot-starter:${mybatisPlusVersion}") compileOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
高版本中把Wrapper分为QueryWrapper、UpdateWrapper、LambdaQueryWrapper、LambdaUpdateWrapper了,EntityWrapper已经废弃了
怎么把数据库 换成mysql呢?
@jackcooper2015
@hb39589961
@529435389
@hb39589961 EntityWrapper
ew = new EntityWrapper (); 没有EntityWrapper,在jar包中也没有找到,需要自己实现Wrapper吗 应该是你的包导入不正确 这是我的导包:求帮忙看看错在哪里了 ext { springBootVersion = '2.0.3.RELEASE' mybatisPlusVersion = "3.0-gamma" }
testCompile group: 'junit', name: 'junit', version: '4.12' compile('org.springframework.boot:spring-boot-starter-jdbc') compile('org.springframework.boot:spring-boot-starter-mail') //compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-websocket') //compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2') runtime('mysql:mysql-connector-java') //compileOnly('org.projectlombok:lombok') //使用后报错,疑似版本问题,该包的引用在common中 testCompile('org.springframework.boot:spring-boot-starter-test')
//使用mybatis plus,需要去掉原来的mybatis包 compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") compile("org.springframework.boot:spring-boot-starter-undertow:${springBootVersion}") //compile("com.h2database:h2:1.4.197") //compile("com.zaxxer:HikariCP:3.2.0") compile("com.baomidou:mybatis-plus-boot-starter:${mybatisPlusVersion}") compileOnly("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
高版本中把Wrapper分为QueryWrapper、UpdateWrapper、LambdaQueryWrapper、LambdaUpdateWrapper了,EntityWrapper已经废弃了
xx谢谢
//Todo 分页完成,向查询的数据中添加字段
IPage
向分页完的数据中添加字段该如何写?
@MissThee 没有深入使用不要瞎比比
@529435389 一般没有你这种需求,不过你可以回写对象
entityWrapper 用or的时候会报 io.shardingjdbc.core.parsing.parser.exception.SQLParsingUnsupportedException: Not supported token 'OR'. 这个异常 怎么解决
v3.0-RC版本的配置文件,有没有啊?
这是啥配置文件?
可以详细解释一下么
mybatisplus 执行更新操作的时候,字段置空,不保存怎么解决
文档该更新了。application.yml 配置文件都是错误的。使用版本时3.0-rc
使用EntityWrapper 封装实体是查询字段中字段拼接成 sys_date AS sysDate
这个是怎么回事?数据库是sqlserver2012的,数据库字段为 sys_date -- AS sysDate
sysDate 两边有个单引号(不是中文的,也不是英文 的)编辑的时候能看到
不错
在springcloud中,服务提供方返回一个mp的Page对象,服务消费方用mp的Page对象来接收时,会报错,代码如下:
@FeignClient("service-user")
public interface ShopUserProvider extends ShopUserApi {
@GetMapping("/user/page")
Page<User> selectByPage(@RequestParam("current") Integer current, @RequestParam("size") Integer size);
}
报错如下:
Error while extracting response for type [com.baomidou.mybatisplus.plugins.Page<com.lace.common.entity.shop.ShopUser>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized field \"pages\" (class com.baomidou.mybatisplus.plugins.Page), not marked as ignorable; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field \"pages\" (class com.baomidou.mybatisplus.plugins.Page), not marked as ignorable (4 known properties: \"size\", \"records\", \"total\", \"current\"])\n at [Source: (PushbackInputStream); line: 1, column: 2262] (through reference chain: com.baomidou.mybatisplus.plugins.Page[\"pages\"])
请问应该如何解决?
请教:AR模式的事物是怎么处理的,模仿写了个针对List的AR。但是事物应该是没用的。
public class MybatisPlusList<E extends Model<E>> extends ArrayList<E> {
public MybatisPlusList(Collection<E> c) {
super(c);
}
public Boolean insertBatch() {
return insertBatch(30);
}
@Transactional
public Boolean insertBatch(int batchSize) {
if (this.size() > 0) {
try {
SqlSession batchSqlSession = this.getSession();
Throwable outThrowable = null;
try {
int size = this.size();
String sqlStatement = this.sqlStatement(SqlMethod.INSERT_ONE);
for (int i = 0; i < size; ++i) {
batchSqlSession.insert(sqlStatement, this.get(i));
if (i >= 1 && i % batchSize == 0) {
batchSqlSession.flushStatements();
}
}
batchSqlSession.flushStatements();
} catch (Throwable throwable) {
outThrowable = throwable;
throw throwable;
} finally {
if (batchSqlSession != null) {
if (outThrowable != null) {
try {
batchSqlSession.close();
} catch (Throwable var15) {
outThrowable.addSuppressed(var15);
}
} else {
batchSqlSession.close();
}
}
}
return true;
} catch (Throwable var18) {
throw new MybatisPlusException("Error: Cannot execute insertBatch Method. Cause", var18);
}
} else {
return true;
}
}
protected SqlSession getSession() {
return SqlHelper.sqlSessionBatch(currentModelClass());
}
protected Class currentModelClass() {
if (this.size() > 0) {
E e = this.get(0);
if (e != null) {
return e.getClass();
}
}
throw new MybatisPlusException("第一个元素不能为空");
}
protected String sqlStatement(SqlMethod sqlMethod) {
return SqlHelper.table(this.currentModelClass()).getSqlStatement(sqlMethod.getMethod());
}
}
@foreveri7 为什么wrapper里没有sqlsegment属性,却可以 ${ew.sqlSegment}调用
有GetSqlSegment方法
Id生成策略IdType.ID_WORKER,Twitter-Snowflake算法需要指定工作机器ID和数据中心ID,在哪里配置?
mp 如何配置 mongodb ? 我刚看了一下好像不支持 mongodb 不知道有没有支持的打算 或者目前已经支持了但是我目前还不知道能否给我发一下使用教程
如果要更新所有字段(部分字段的值为null)要怎么做,看最新版里已经没有原来的updateAllClumn这样的方法了?
updateAllColumnById
自定义添加的SQL,map-underscore-to-camel-case=true设置不生效
您好,最近在搭建框架的时候看中了mybatis-plus。但是在进行多数据源的配置的时候,事务管理出现了问题。也就是在方法执行的时候抛出异常,单数据源的事务不回滚。可否解答下,谢谢
而且,在配置数据源切换的时候,采用的是切面进行切换的。但是必须自己封装一下service的方法,不能用,mybatis-plus原生service的api。感觉这样丢弃了我使用mybatis-plus带来的好处。封装类似下面的代码:
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {
@Autowired
private ServiceTemplate serviceTemplate;
@Override
@Transactional
public boolean deleteAll() {
return retBool(baseMapper.deleteAll());
}
@Override
public IPage<Car> queryList(CarParam carParam) {
return this.selectPage(new Page<Car>(carParam.getPage() - 1, carParam.getPageSize()), null);
}
@Override
public boolean deleteById(CarParam carParam) {
return this.deleteById(carParam.getId());
}
@Override
public boolean update(CarParam carParam) {
return this.updateById(carParam.getCar());
}
}
mybatisx..jar 这个网站应该提供一个下载链接吧,很多电脑是连不了国外的网站的。
你好。我用的是方式一分页方式,但调用pageResult.setAsc(false)方法后,排序结果并没有改变?哪里出了问题?
Page
一对多的分页有好的解决方案吗,limit总是会拼接在最后面
一对多如何分页
一对多如何分页
limit语句永远都拼接在最后
@Select("${sql}") List<Map<String,Object>> searchDataBySql(@Param("sql") String sql); 返回值错误,在查询到1条数据(多条数据的时候没问题)的时候,返回List<Map<String,Object>>的list.size()=0? 还有返回 int类型的值也是0 什么原因?
使用版本3.0-gamma @select("${sql}") List<Map<String,Object>> searchDataBySql(@param("sql") String sql); int searchDataBySql(@param("sql") String sql); 两种方式查询结果错误,查询到了0条数据,但是打印出来的log信息又是有一条数据,同时直接通过sql语句到数据库查 有1条数据,求教怎么解决
今天发现多数据源的实现了,真的很开心呀
@TomyJx 今天发现多数据源的实现了,真的很开心呀
跟mp有毛关系
http://mp.baomidou.com/#/
An enhanced toolkit of Mybatis to simplify development