mybatis中实体类,po类继承另一个po类的情况

CREATE TABLE tbl_admin(
	id int(12) NOT NULL AUTO_INCREMENT,
	username VARCHAR(32) NOT NULL COMMENT '用户名',
	password VARCHAR(32) NOT NULL COMMENT '密码',
	create_time VARCHAR(20) DEFAULT 0 COMMENT '创建时间',
	status int(2) DEFAULT 1 COMMENT '是否启用 0:停用;1:启用;',
	shenhe int(2) DEFAULT 0 COMMENT '当usertype=1时, 0:管理员自己创建; >0时审核 1:未审核;2:审核通过;3:审核不通过;',
	remark VARCHAR(32) DEFAULT '' COMMENT '备注',
	usertype int(2) DEFAULT 0 COMMENT '0:管理员;1:商家',
	PRIMARY KEY (id)
)ENGINE=INNODB COMMENT '管理员表';

父类

public class BaseAdmin {
	private Integer id;
	private String username;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	
	
}

子类

public class Admin extends BaseAdmin {
	//密码
	private String password;
	//创建时间
	private String create_time;
	//状态
	private int status;
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getCreate_time() {
		return create_time;
	}
	public void setCreate_time(String create_time) {
		this.create_time = create_time;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	
	
}


情况一

dao

@Mapper
public interface IAdminDao {

	public Admin query(String username);
}

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ldgx.eshop.dao.IAdminDao">
	<!-- 根据条件查询管理员 -->
	<select id="query" resultType="com.ldgx.eshop.entity.Admin">
		select * from tbl_admin 
		<where>
			<if test="_parameter != null and !_parameter.equals("")">
				username = #{_parameter}
			</if>
		</where>
		limit 1
	</select>
</mapper>

这种可以



情况二

也可以

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ldgx.eshop.dao.IAdminDao">

	<resultMap id="adminMap" type="com.ldgx.eshop.entity.Admin">
		<id column="id" jdbcType="INTEGER" property="id"/>
		<result column="username" jdbcType="VARCHAR" property="username"/>
		<result column="password" jdbcType="VARCHAR" property="password"/>
		<result column="create_time" jdbcType="VARCHAR" property="create_time"/>
		<result column="status" jdbcType="INTEGER" property="status"/>
	</resultMap>
	<!-- 根据条件查询管理员 -->
	<select id="query" resultMap="adminMap">
		select * from tbl_admin 
		<where>
			<if test="_parameter != null and !_parameter.equals("")">
				username = #{_parameter}
			</if>
		</where>
		limit 1
	</select>
</mapper>



展开阅读全文

没有更多推荐了,返回首页