[JAVA] Get the ID of automatic numbering

Get the automatically numbered ID



		//Method for automatic numbering acquisition
		@PostConstruct
		public void init() {
			SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert((JdbcTemplate) template.getJdbcOperations());
			SimpleJdbcInsert withTableName = simpleJdbcInsert.withTableName("orders");
			insert = withTableName.usingGeneratedKeyColumns("id");	
	}

After inserting, get the ID assigned by automatic numbering and return


public Order insert(Order order) {

    //Domain name and SQL? If there is a part, it will enter automatically
     SqlParameterSource param = new BeanPropertySqlParameterSource(order);
   
    //executeAndReturnKey executes the insert statement without permission
     Number key = insert.executeAndReturnKey(param);

     order.setId(key.intValue());

	return order;
}

I will leave it as a memorandum. If you have any suggestions, please let me know.

Recommended Posts

Get the ID of automatic numbering
[Swift] How to get the document ID of Firebase
Get only the ID of the container specified by docker ps
How to get the id of PRIMAY KEY auto_incremented in MyBatis
Get the result of POST in Java
[Java] Get the day of the specific day of the week
The identity of params [: id] in rails
[Swift] Get the height of Safe Area
[Java] Get the length of the surrogate pair string
The basics of the App Store "automatic renewal subscription"
How to get today's day of the week
Get your version number in the Android app
[Swift] Get the number of steps with CMP edometer
Get the ID of automatic numbering
[Java] How to get the authority of the folder
[Java] How to get the URL of the transition source
Get the URL of the HTTP redirect destination in Java
[Swift] Get the number of steps with CMP edometer
[Kotlin] Get the argument name of the constructor by reflection
Get the name of the test case in the JUnit test class
Judgment of the calendar
[Java] How to get the maximum value of HashMap
The world of clara-rules (4)
The world of clara-rules (1)
The world of clara-rules (3)
[Java] Get the file in the jar regardless of the environment
[Android] How to get the setting language of the terminal
The world of clara-rules (5)
The idea of quicksort
Ruby, Nokogiri: Get the element name of the selected node
[Rails] How to get the contents of strong parameters
I can't get out of the Rails dbconsole screen
Get the URL of the HTTP redirect destination in Ruby
Automatic assignment of name attribute and id attribute by form_with
The idea of jQuery
Get the object name of the instance created by the new operator
Get to the abbreviations from 5 examples of iterating Java lists
(Ruby on Rails6) Display of the database that got the id of the database
[Swift] Get the timing when the value of textField is changed
[jsoup] How to get the full amount of a document
About the handling of Null
Docker monitoring-explaining the basics of basics-
About the description of Docker-compose.yml
Understand the basics of docker
The play of instantiating java.lang.Void
Explanation of the FizzBuzz problem
The basics of Swift's TableView
Median of the three values
The illusion of object orientation
Stop automatic update of Ubuntu
Switch the version of bundler
I checked the automatic unit test creation tool (end of 2019 version)
[Rails] How to get the URL of the transition source and redirect
[Java1.8 +] Get the date of the next x day of the week with LocalDate
[Java] Get the dates of the past Monday and Sunday in order
[Swift5] How to get an array and the complement of arrays
Get a proxy instance of the component itself in Spring Boot
[Swift UI] How to get the startup status of the application [iOS]
How to get the contents of Map using for statement Memorandum
Get the public URL of a private Flickr file in Java
Read the implementation of Rails 6 multi-DB automatic switching (ActiveRecord :: Middleware :: DatabaseSelector)
How to get the length of an audio file in java
Get the acceleration and bearing of the world coordinate system on Android