SpringBoot通过java代码创建Mysql表

mac2025-11-07  17

package com.zcw.zcw_springboot.zcw_springboot.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * @author zhaocunwei * @ClassName: UserController * @Description: TODO * @date 2019/11/1 18:14 */ @RestController public class UserController { @Autowired private JdbcTemplate jdbcTemplate; /** * execute方法用来直接操作sql语句 */ @GetMapping("createTable") public String createTable(){ String sql="create table user\n" + "(\n" + "id int(11) primary key,\n" + "user_name varchar(25),\n" + "user_password int(11)\n" + ");"; jdbcTemplate.execute(sql); return "创建user表成功"; } }
最新回复(0)