Spring Boot中mybatis insert 如何获得自增id

https://www.cnblogs.com/quan-coder/p/8728410.html

注意要显式设置主键,通过:

@Options(useGeneratedKeys = true, keyProperty = "id")

将id设置为主键返回。

https://blog.csdn.net/suwu150/article/details/52896496

一个示例(Mapper中的代码片段):

	@Insert("insert into tz_lawsuits " + 
			"(credit_cooperative, change_date, admin, borrower, borrower_id, guarantee, litigation_principal, type, starting_end_date," + 
			" lawyer, action_date, litigation_costs, attorney_fees, advance, verdict_id, implementation_date, award_id, takeback_agent_fee," + 
			" takeback_litigation_costs, takeback_principal, outstanding_principal, responsible_person)" + 
			" values" + 
			"(#{credit_cooperative}, #{change_date}, #{admin}, #{borrower}, #{borrower_id}, #{guarantee}, #{litigation_principal}, #{type}, #{starting_end_date}," + 
			" #{lawyer}, #{action_date}, #{litigation_costs}, #{attorney_fees}, #{advance}, #{verdict_id}, #{implementation_date}, #{award_id}, #{takeback_agent_fee}," + 
			" #{takeback_litigation_costs}, #{takeback_principal}, #{outstanding_principal}, #{responsible_person})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	Integer insertTzLawsuitsObject(TzLawsuits tzLawsuits);
posted @ 2018-10-09 15:23  zifeiy  阅读(5484)  评论(0编辑  收藏  举报