Vue端:
<el-select
v-model="year"
placeholder="请选择"
popper-class="popperClassA"
@change="selectChange">
<el-option
v-for="(item, index) in yearsList"
:key="index"
:label="item.label"
:value="item.value"/>
</el-select>
</el-select>
data() {
return {
yearsList: [],
year: new Date().getFullYear() //默认展示当前年
}
},
created() {
const _this = this
_this.years()
},
methods: {
//年份select下拉列表设置
years() {
const _this = this
_this.initSelectYear(new Date().getFullYear())
},
initSelectYear(year) {
const _this = this
_this.yearsList = []
for (let i = 0; i < 11; i++) { //截止当前年往前查询10年
_this.yearsList.push({ value: (year - i), label: (year - i) + '年' })
}
}
}
Sql:
<select id="count" parameterType="Map" resultType="int">
SELECT count(1) FROM XXXX
<where>
<if test="year != '' and year != null">
AND YEAR(time) = #{year} // 日期格式只取年份
</if>
</where>
</select>