类似mysql 的like
// 原生查询 {name:/名字/} // java 驱动查询 document.put("page_html", Pattern.compile("名字"));
package com.example.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.MongoTransactionManager; @Configuration public class TransactionConfig { @Bean MongoTransactionManager transactionManager(MongoDbFactory factory){ return new MongoTransactionManager(factory); } }
@Transactional(rollbackFor = Throwable.class) public void saveTest(Mongo test) { mongoTemplate.save(test); int i = 1/0; }
在启动类上加上事务注解@EnableTransactionManagement
。