下面列出了org.apache.ibatis.annotations.Insert#org.apache.ibatis.annotations.SelectKey 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Insert("INSERT INTO plugin_devicelog_settings_rules (" +
" settingId, " +
" name, " +
" active, " +
" applicationId, " +
" severity, " +
" filter, " +
" groupId, " +
" configurationId " +
") " +
"VALUES (" +
" #{settingId}, " +
" #{name}, " +
" #{active}, " +
" #{applicationId}, " +
" #{severity}, " +
" #{filter}, " +
" #{groupId}, " +
" #{configurationId} " +
")")
@SelectKey( statement = "SELECT currval('plugin_devicelog_settings_rules_id_seq')",
keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPluginSettingsRule(PostgresDeviceLogRule rule);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table T_COFFEE
*
* @mbg.generated Sun Dec 08 00:33:16 CST 2019
*/
@Insert({
"insert into T_COFFEE (NAME, PRICE, ",
"CREATE_TIME, UPDATE_TIME)",
"values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT,typeHandler=com.zuozewei.springbootdatadrivendemo.handler.MoneyTypeHandler}, ",
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
})
@SelectKey(statement="CALL IDENTITY()", keyProperty="id", before=false, resultType=Long.class)
int insert(Coffee record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table t_coffee
*
* @mbg.generated Mon Dec 16 18:17:01 CST 2019
*/
@Insert({
"insert into t_coffee (name, price, ",
"create_time, update_time)",
"values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT,typeHandler=com.zuozewei.springbootdatabackuprecoverydemo.handler.MoneyTypeHandler}, ",
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
})
@SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
int insert(Coffee record);
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
Class<?> resultTypeClass = selectKeyAnnotation.resultType();
StatementType statementType = selectKeyAnnotation.statementType();
String keyProperty = selectKeyAnnotation.keyProperty();
String keyColumn = selectKeyAnnotation.keyColumn();
boolean executeBefore = selectKeyAnnotation.before();
// defaults
boolean useCache = false;
KeyGenerator keyGenerator = new NoKeyGenerator();
Integer fetchSize = null;
Integer timeout = null;
boolean flushCache = false;
String parameterMap = null;
String resultMap = null;
ResultSetType resultSetTypeEnum = null;
SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
SqlCommandType sqlCommandType = SqlCommandType.SELECT;
assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
flushCache, useCache, false,
keyGenerator, keyProperty, keyColumn, null, languageDriver, null);
id = assistant.applyCurrentNamespace(id, false);
MappedStatement keyStatement = configuration.getMappedStatement(id, false);
SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
configuration.addKeyGenerator(id, answer);
return answer;
}
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
Class<?> resultTypeClass = selectKeyAnnotation.resultType();
StatementType statementType = selectKeyAnnotation.statementType();
String keyProperty = selectKeyAnnotation.keyProperty();
String keyColumn = selectKeyAnnotation.keyColumn();
boolean executeBefore = selectKeyAnnotation.before();
// defaults
boolean useCache = false;
KeyGenerator keyGenerator = new NoKeyGenerator();
Integer fetchSize = null;
Integer timeout = null;
boolean flushCache = false;
String parameterMap = null;
String resultMap = null;
ResultSetType resultSetTypeEnum = null;
SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
SqlCommandType sqlCommandType = SqlCommandType.SELECT;
assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
flushCache, useCache, false,
keyGenerator, keyProperty, keyColumn, null, languageDriver, null);
id = assistant.applyCurrentNamespace(id, false);
MappedStatement keyStatement = configuration.getMappedStatement(id, false);
SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
configuration.addKeyGenerator(id, answer);
return answer;
}
@Insert({"INSERT INTO customers (name, description, filesDir, master, prefix, registrationTime) " +
"VALUES (#{name}, #{description}, #{filesDir}, FALSE, #{prefix}, #{registrationTime})"})
@SelectKey( statement = "SELECT currval('customers_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insert(Customer customer);
@Insert({"INSERT INTO applications (name, pkg, showIcon, system, customerId, runAfterInstall, runAtBoot, type, iconText, iconId) " +
"VALUES (#{name}, #{pkg}, #{showIcon}, #{system}, #{customerId}, #{runAfterInstall}, #{runAtBoot}, #{type}, #{iconText}, #{iconId})"})
@SelectKey( statement = "SELECT currval('applications_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertApplication(Application application);
@Insert({"INSERT INTO applicationVersions (applicationId, version, url) " +
"VALUES (#{applicationId}, #{version}, #{url})"})
@SelectKey( statement = "SELECT currval('applicationVersions_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
int insertApplicationVersion(ApplicationVersion version);
@Insert({"INSERT INTO users (login, email, name, password, customerId, userRoleId, allDevicesAvailable) " +
"VALUES (#{login}, #{email}, #{name}, #{password}, #{customerId}, #{userRole.id}, #{allDevicesAvailable})"})
@SelectKey( statement = "SELECT currval('users_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insert(User user);
@Insert("INSERT INTO icons (customerId, name, fileId) VALUES (#{customerId}, #{name}, #{fileId})")
@SelectKey(statement = "SELECT currval('icons_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class)
int insertIcon(Icon icon);
@SelectKey( statement = "SELECT currval('configurations_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertConfiguration(Configuration configuration);
@Insert("INSERT INTO uploadedFiles (customerId, filePath, uploadTime) VALUES (#{customerId}, #{filePath}, EXTRACT(EPOCH FROM NOW()) * 1000)")
@SelectKey(statement = "SELECT currval('uploadedFiles_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class)
int insertFile(UploadedFile file);
@Insert("INSERT INTO pushMessages (messageType, deviceId, payload) " +
"VALUES (#{messageType}, #{deviceId}, #{payload})")
@SelectKey( statement = "SELECT currval('pushmessages_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPushMessage(PushMessage message);
@Insert("INSERT INTO plugin_devicelog_settings (customerId, logsPreservePeriod) " +
"VALUES (#{customerId}, #{logsPreservePeriod})")
@SelectKey( statement = "SELECT currval('plugin_devicelog_settings_id_seq')",
keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPluginSettings(PostgresDeviceLogPluginSettings postgresDeviceLogPluginSettings);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id, name_fred from table2 where id = identity()", keyProperty="nameId,generatedName", keyColumn="ID,NAME_FRED", before=false, resultType=Map.class)
int insertTable2WithSelectKeyWithKeyMap(Name name);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id as nameId, name_fred as generatedName from table2 where id = identity()", keyProperty="nameId,generatedName", before=false, resultType=Name.class)
int insertTable2WithSelectKeyWithKeyObject(Name name);
@Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3(Name name);
@InsertProvider(type=SqlProvider.class,method="insertTable3_2")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3_2(Name name);
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred from table2 where id = #{nameId}", keyProperty="generatedName", keyColumn="NAME_FRED", before=false, resultType=String.class)
int updateTable2WithSelectKeyWithKeyMap(Name name);
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred as generatedName from table2 where id = #{nameId}", keyProperty="generatedName", before=false, resultType=Name.class)
int updateTable2WithSelectKeyWithKeyObject(Name name);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id, name_fred from table2 where id = identity()", keyProperty="nameId,generatedName", keyColumn="ID,NAME_FRED", before=false, resultType=Map.class)
int insertTable2WithSelectKeyWithKeyMap(Name name);
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id as nameId, name_fred as generatedName from table2 where id = identity()", keyProperty="nameId,generatedName", before=false, resultType=Name.class)
int insertTable2WithSelectKeyWithKeyObject(Name name);
@Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3(Name name);
@InsertProvider(type=SqlProvider.class,method="insertTable3_2")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3_2(Name name);
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred from table2 where id = #{nameId}", keyProperty="generatedName", keyColumn="NAME_FRED", before=false, resultType=String.class)
int updateTable2WithSelectKeyWithKeyMap(Name name);
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred as generatedName from table2 where id = #{nameId}", keyProperty="generatedName", before=false, resultType=Name.class)
int updateTable2WithSelectKeyWithKeyObject(Name name);
/**
* 添加商品
* @param product
* @return Long 表示影响的行数
*/
@Insert("insert into product (product_Name, price,product_Brief) values(#{productName}, #{price}, #{productBrief})")
@Options(useGeneratedKeys=true,keyProperty="id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
public Long insert(Product product);
/**
* 新增
* 所有字段传入 model.params,不能为空
* @param model
* @return
*/
@InsertProvider(method = "insert", type = SqlTemplate.class)
@SelectKey(before=false,keyProperty="params.id",resultType=Object.class,statementType=StatementType.STATEMENT,statement="SELECT LAST_INSERT_ID() AS id")
int insert(Table model);