-
@PostConstruct 将在依赖注入完成后被自动调用
-
注意 : 使用该中方式生成SQL时, dao + Mapper 需要正常编写
private final static String DATAEXPORT_NAME_SPACE = "nameSpace+id";
@Autowired
private SqlSessionFactory sessionFactory;
private MappedStatement mappedStatement;
@PostConstruct
public void init() {
this.mappedStatement = sessionFactory.getConfiguration().getMappedStatement(DATAEXPORT_NAME_SPACE);
}
private String getSql(DataExportVo dataExportVo) {
return mappedStatement.getBoundSql(dataExportVo).getSql();
}
Mapper :Demo
-
只需要写< select >, 不需要配置 resultMap
<select id="exeDataExport" parameterType="com.weidiango.api.supplier.operation.vo.DataExportVo">
SELECT
*
FROM
表名
<where>
<--集合-->
<if test='supplierIdList != null and supplierIdList.size > 0 '>
AND suppliers_id IN
<foreach collection="supplierIdList" item="item" open="(" separator="," close=")">
'${item}'
</foreach>
</if>
<--字符串-->
<if test='createTimeS != null and createTimeS != "" '>
AND
create_time >= '${createTimeS}'
</if>
</where>
limit 0,1000000
</select>