版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/weixin_43014205/article/details/87938196
在使用mybatis代码生成器时,若生成的字段要为布尔类型,则在设计表时,将字段属性设置为tinyint 长度设为1 这样 生成的domain中的 相应字段类型为布尔类型
如数据库中的字段类型为date或者datetime类型 该如何将其转成json类型传到前端?
在实体类的字段上加上 @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") 即可
在mybatis多表联查,假设两个表中都有 id 这个字段 且未加区分,那么在查询时要给对应的字段起别名(可以在前面加x_),并且在封装的结果类型,可以设置 cloumsprefix x_ 及在关联对象的字段前加上前缀
<select id="selectAll" resultMap="BaseResultMap" >
select e.id, e.username, e.inputtime, e.tel, e.email, e.state, e.admin,
d.id as d_id,
d.`name` as d_name
from employee as e LEFT JOIN department as d on e.dep_id=d.id
</select>
<resultMap id="BaseResultMap" type="com.itlike.domain.Employee" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="username" property="username" jdbcType="VARCHAR" />
<result column="inputtime" property="inputtime" jdbcType="TIMESTAMP" />
<result column="tel" property="tel" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="BIT" />
<result column="admin" property="admin" jdbcType="BIT" />
<!--加上前缀 会自动的把数据库中的 id 和 name 给加上d_
即将数据库中的 d_name 赋值给name d_id 赋值给id
-->
<association property="department" javaType="com.itlike.domain.Department" columnPrefix="d_">
<result property="id" column="id"/>
<result property="name" column="name"/>
</association>
</resultMap>