spring boot集成tk.mybatis 返回主键(oracle序列)

spring boot启动类代码 (重点:删除@MapperScan(basePackages = “com.zr.mapper”) 注解)`

import java.util.Properties;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
 
import com.github.pagehelper.PageHelper;
 
import tk.mybatis.spring.mapper.MapperScannerConfigurer;
 
@EnableScheduling
@SpringBootApplication // 启动
@ServletComponentScan // 拦截器
@EnableTransactionManagement // 事务管理
// @MapperScan(basePackages = "com.zr.mapper")
public class Startup {
 
	@Bean
	public PageHelper pageHelper() {
		PageHelper pageHelper = new PageHelper();
		Properties p = new Properties();
		p.setProperty("offsetAsPageNum", "true");
		p.setProperty("rowBoundsWithCount", "true");
		p.setProperty("reasonable", "true");
		p.setProperty("dialect", "oracle");
		pageHelper.setProperties(p);
		return pageHelper;
	}
 
	/**重点**/
	@Bean
	public MapperScannerConfigurer mapperScannerConfigurer() {
		MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
		mapperScannerConfigurer.setBasePackage("com.zr.mapper");
		Properties propertiesMapper = new Properties();
		// 通用mapper位置,不要和其他mapper、dao放在同一个目录
		propertiesMapper.setProperty("mappers", "com.zr.bean.MyMapper");
		propertiesMapper.setProperty("notEmpty", "false");
		// 主键UUID回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER)
		propertiesMapper.setProperty("ORDER", "BEFORE");
		mapperScannerConfigurer.setProperties(propertiesMapper);
		return mapperScannerConfigurer;
	}
	public static void main(String[] args) {
		SpringApplicationBuilder builder = new SpringApplicationBuilder(Startup.class);
		// 修改Banner的模式为OFF
		builder.bannerMode(Banner.Mode.OFF).run(args);
	}
 
}

实体类

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "select SEQ_ID.nextval from dual")//前提是先创建了oracle序列
private Long id;
private String name;

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值