前面用 jpa 都是在属性上加注解 @Column(name=“name”),mybatis 不能这么用,所以要加上如下配置
mybatis:
configuration:
#配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性。
map-underscore-to-camel-case: true
查询方法
@Mapper
public interface BrandMapper {
@Select("select name from qs_brand where name = #{brandName})
String findBrandName(@Param("brandName") String brandName);
}
mybatis 依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
参考:https://zhuanlan.zhihu.com/p/31015559