branch.php <?php namespace app\models; use Yii; /** * This is the model class for table "branch". * * @property integer $id * @property string $name * */ class Branch extends \yii\db\ActiveRecord { /** * @inheritdoc */ public static function
先说一下没有注解的 先给出实体类: public class City { private int city_id; private String city_name; public int getCity_id() { return city_id; } public void setCity_id(int city_id) { this.city_id = city_id; } public String getCity_name() { return city_name; } public
postgresql不支持last_insert_id()方法,恶心到啦: 不过还好它有其他的解决方案: 创建一个测试数据表: CREATE TABLE test.test18 ( id serial NOT NULL, ddd character varying ) 一.先过去不重复的主键id,然后再插入 获取他的Sequence,select nextval('test.test18_id_seq'),然后再插入即可! 二.返回主键id insert into test.test18 (dd
需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值. 方法:在mapper中指定keyProperty属性,示例如下: <insert id="insertAndGetId" useGeneratedKeys="true" keyProperty="userId" parameterType="com.chenzhou.mybatis.User"> insert into us
一个自增长ID的对象被save或者persist后,会返回其主键ID: Department department = new Department(); department.setName("xxxxxxx"); session.persist(department); System.out.println("id = " + department2.getId()); Department department2 = new Department(); dep
Mysql数据库表的自增主键ID号乱了,需要重新排列. 原理:删除原有的自增ID,重新建立新的自增ID. 1,删除原有主键: ALTER TABLE `table_name` DROP `id`; 2,添加新主键字段: ALTER TABLE `table_name` ADD `id` MEDIUMINT( ) NOT NULL FIRST; 3,设置新主键: ALTER TABLE `table_name` MODIFY COLUMN `id` MEDIUMINT( ) NOT NULL AU