请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Strom操作数据库新增,主键可以不写吗?

Strom操作数据库,新增的时候 ,与数据的字段要一一对应 ,每个都要有占位,如果id是主键自增的该如何写呢?

正在回答 回答被采纳积分+3

1回答

提问者 半步不多行 2020-03-12 01:47:40

问题删不了,找到答案了。

If your storm tuple only has fields for a subset of columns i.e. if some of the columns in your table have default values and you want to only insert values for columns with no default values you can enforce the behavior by initializing the SimpleJdbcMapper with explicit columnschema. For example, if you have a user_details table create table if not exists user_details (user_id integer, user_name varchar(100), dept_name varchar(100), create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP); In this table the create_time column has a default value. To ensure only the columns with no default values are inserted you can initialize the jdbcMapper as below:

List<Column> columnSchema = Lists.newArrayList(
    new Column("user_id", java.sql.Types.INTEGER),
    new Column("user_name", java.sql.Types.VARCHAR),
    new Column("dept_name", java.sql.Types.VARCHAR)); 
JdbcMapper simpleJdbcMapper = new SimpleJdbcMapper(columnSchema);


1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号