若依Vue学习笔记

2023-02-23  本文已影响0人  syserr

1.代码生成导入错误

代码生成过程中用到了MySql的系统库information_schema以及若依自己的库,如果两者字符集信息不同,则会报错;

创建若依数据库时参考information_schema库的字符集,确保两者一致,一般同为utf8_genreal_ci或utf8_unicode_ci

2.自定义业务表

准备好业务表SQL,参考 代码生成 部分指导,导出代码包,然后执行下述步骤

3.自定义业务包路径问题

如果自定义业务包路径不是com.ruoyi开头,则上述操作后,系统运行会出错,管理界面可以出来,但前后台不通;原因是新增的业务逻辑没有加载到,需要手动做如下更改(假设新增业务包com.litian.app):

mybatis:
    # 搜索指定包别名
    typeAliasesPackage: com.ruoyi.**.domain, com.litian.**.domain
@ComponentScan({"com.ruoyi", "com.litian"})
@MapperScan({"com.litian.**.mapper"})
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class RuoYiApplication

4.前端页面中使用字典

如果在前端页面中使用到了字典,不管是自定义还是系统预置,均需要手工声明,否则若依的表现就是页面挂起空白;如页面中使用到了如下字典内容:

        <el-form-item label="爱好" prop="studentHobby">
          <el-select v-model="form.studentHobby" placeholder="请选择爱好">
            <el-option
              v-for="dict in dict.type.app_user_hobby"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

其中用到了字典类型app_user_hobby,则需要在当前页面的导出部分声明(多值用逗号分隔):

export default {
  name: .....,
  dicts: ['app_user_hobby'],

5.导出表格选中行

默认情况下,若依会根据当前的查询条件导出所有数据(会把查询参数请求到后台),但是忽略了界面的行选择信息;因此需要手工处理导出选中行的功能;

    <select id="selectSysStudentByStudentIds"  resultMap="SysStudentResult">
        <include refid="selectSysStudentVo"/>
        where student_id in
        <foreach collection="array" item="id" index="index" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    /**
     * 查询学生信息
     *
     * @param ids 学生信息主键
     * @return 学生信息
     */
    public List<SysStudent> selectSysStudentByStudentIds(String[] ids);
    /**
     * 导出选中学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('app:student:export')")
    @Log(title = "学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exports")
    public void export(HttpServletResponse response, @RequestParam(value = "ids") String ids)
    {
        List<SysStudent> list = sysStudentService.selectSysStudentByStudentIds(ids.split(","));
        ExcelUtil<SysStudent> util = new ExcelUtil<SysStudent>(SysStudent.class);
        util.exportExcel(response, list, "学生信息数据");
    }
      if(this.ids.length > 0){
        this.download('app/student/exports', {'ids':this.ids.join(',')}, `student_${new Date().getTime()}.xlsx`)
      }else {
        this.download('app/student/export', {
          ...this.queryParams
        }, `student_${new Date().getTime()}.xlsx`)
      }

至于,为何将ids拼装后再拆分使用,是因为若依的通用download方法会将请求参数进行转换,会将数组对象拆开,后端不方便处理,所以前端将数组拼装成字符串,后端再拆分使用。

上一篇 下一篇

猜你喜欢

热点阅读