表 tb_brand
实体类 Brand属性名
解决方式一(为表字段取别名)
// 根据字段id查询@Select("select id, brand_name as brandName, company_name as companyName from tb_brand where id = #{id}")Brand selectById(int id);
解决方式二(添加注解@Results)
@Results(id = "brandMapper", value = {@Result(id = true, column = "id", property = "id"),// 这里的id=true是主键@Result(column = "brand_name", property = "brandName"),@Result(column = "company_name", property = "companyName")})@Select("select id, brand_name, company_name from tb_brand where id = #{id}")Brand selectById(int id);
Results注解中有两个常用的参数,一个是id,另一个是value。id为唯一标识,当其他地方需要使用这个Results时,这时我们就可以通过@ResultMap()注解中传入Results注解的参数id来引用Results注解中的内容。
@ResultMap(value = "brandMapper")@Select("select * from tb_brand")List<Brand> selectAll();// 查询所有