当前位置:   article > 正文

Vue+Axios+SSM框架实现增删改查与文件上传_vue增删改查axios

vue增删改查axios

总结

        随手搭建一个Vue+SSM框架,实现增删改查和上传、预览图片的功能,这里把用到的技术点和工具罗列一下:

前端:

1. 使用VUE作为基础框架。

2. 使用elementUI的一些组件,搭建表格、弹框、表单等。

3. 使用form-generator,在线搭建属于自己的form表单,可以下载自定义的from表单代码,网址:https://mrhj.gitee.io/form-generator/#/

4. 使用axios,将前端数据封装,异步传输给后端。

5. 使用vue实现三级联动、省市区三级信息查询、回显功能。

6. 使用element的组件实现分页查询、文件上传的功能。

后端:

1. 使用ssm框架,搭建分页查询、增删改接口。

2. 定义上传接口,将文件上传至远程服务器。

3. 使用mybatis的逆向工程,生成mybatis的mapper文件、bean实体、mapper接口。

访问以下地址下载源码:

链接:https://pan.baidu.com/s/163wHTpcdLdOfCUSg1PqMgg?pwd=4fb1 
提取码:4fb1 
--来自百度网盘超级会员V3的分享

准备工作

创建数据库表

数据库DDL语句如下:

  1. CREATE TABLE
  2. gameuser
  3. (
  4. usrId INT NOT NULL AUTO_INCREMENT,
  5. usrLoginNm VARCHAR(183),
  6. usrLoginPwd VARCHAR(183),
  7. usrNm VARCHAR(183),
  8. usrCardNum VARCHAR(18),
  9. usrAddr VARCHAR(183),
  10. usrBirDate DATE,
  11. usrHobby VARCHAR(183),
  12. usrDetail VARCHAR(183),
  13. usrFileUrl VARCHAR(183),
  14. PRIMARY KEY (usrId)
  15. )
  16. ENGINE=InnoDB DEFAULT CHARSET=utf8 DEFAULT COLLATE=utf8_general_ci;

搭建前端开发环境

1. 首先,我们需要访问地址:https://mrhj.gitee.io/form-generator/#/

    利用此网站定义我们的form表单,生成完毕后将vue文件下载到本地,后面我们会导入到项目中。

 2. 在本地搭建vue项目,使用黑窗口命令:vue create vueproject 创建前端Vue项目:

3. 在项目的创建目录下运行命令:npm i element-ui -S  安装elementUI

4. 项目中需要与后端接口通信,需要使用的技术为axios,执行 npm install axios 命令安装axios:

5. 使用Hbuilder打开前端项目,在package.json文件的rules中添加以下内容,去掉esline校验:

       "vue/no-unused-components": "off",
      "no-mixed-spaces-and-tabs": 0

6. 解决跨域问题,修改前端配置 vue.config.js 增加跨域配置项,跨域的解决方案有很多,这里选择使用前端代理实现跨域问题,配置以下内容:

  1. devServer: {//配置代理 解决跨域问题
  2. proxy: {
  3. '/api': {
  4. // 此处填写项目的访问地址
  5. target: 'http://localhost:8082/Ajaxd01',
  6. // 允许跨域
  7. changeOrigin: true,
  8. ws: true,
  9. pathRewrite: {
  10. '^/api': ''
  11. }
  12. }
  13. }
  14. }

7. 因为需要用到elementUI,此处在main.js中导入elementUI相关的信息,此处小编为了省事儿,就直接全部引入了,大家根据自己情况选择按需引入还是全部引入(具体引用方式可参考官网):

  1. //引入elementUI相关的组件
  2. import ElementUI from 'element-ui';
  3. import 'element-ui/lib/theme-chalk/index.css';
  4. Vue.use(ElementUI);//use之后生效

8. 在main.js引入axios的相关包并use。

  1. //引入axios
  2. import axios from 'axios'
  3. //配置请求的根路径
  4. axios.defaults.baseURL = '/api/'
  5. // 原型上挂载axios, 所有组件都可以通过this.$http来请求
  6. Vue.prototype.$http = axios
  7. Vue.use(axios)

9. 最终mai.js中的配置如下:

10.  我们来运行一下项目试试看,输入命令:npm run serve 项目可以正常运行即可

11. 至此,可以访问前端项目,前端项目准备工作结束,可以进行VUE项目的开发了。

搭建后端开发环境

1. 后端采用传统的SSM框架实现文件的上传下载、三级联动、以及普通的增删改查,这里我们会利用Mybatis的逆向工程为我们提供支持,以简化我们的开发效率。

2. 首先,我们先来创建一个普通SSM的Maven项目,按照图示步骤创建:

3. 创建maven web 项目,补充缺失目录,java、resources、test目录。

4. 更新web.xml中的约束:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  5. version="4.0">
  6. </web-app>

5. 创建各个层的包:controller、bean、service、impl、mappe

6. 导入maven相关的依赖:

  1. <!--Spring核心包-->
  2. <dependency>
  3. <groupId>org.springframework</groupId>
  4. <artifactId>spring-context</artifactId>
  5. <version>5.3.5</version>
  6. </dependency>
  7. <!--spring切面 包-->
  8. <dependency>
  9. <groupId>org.springframework</groupId>
  10. <artifactId>spring-aspects</artifactId>
  11. <version>5.3.5</version>
  12. </dependency>
  13. <!--aop联盟包-->
  14. <dependency>
  15. <groupId>aopalliance</groupId>
  16. <artifactId>aopalliance</artifactId>
  17. <version>1.0</version>
  18. </dependency>
  19. <!--德鲁伊连接池-->
  20. <dependency>
  21. <groupId>com.alibaba</groupId>
  22. <artifactId>druid</artifactId>
  23. <version>1.1.10</version>
  24. </dependency>
  25. <!--mysql驱动-->
  26. <dependency>
  27. <groupId>mysql</groupId>
  28. <artifactId>mysql-connector-java</artifactId>
  29. <version>8.0.22</version>
  30. </dependency>
  31. <!--springJDBC包-->
  32. <dependency>
  33. <groupId>org.springframework</groupId>
  34. <artifactId>spring-jdbc</artifactId>
  35. <version>5.3.5</version>
  36. </dependency>
  37. <!--spring事务控制包-->
  38. <dependency>
  39. <groupId>org.springframework</groupId>
  40. <artifactId>spring-tx</artifactId>
  41. <version>5.3.5</version>
  42. </dependency>
  43. <!--orm映射依赖-->
  44. <dependency>
  45. <groupId>org.springframework</groupId>
  46. <artifactId>spring-orm</artifactId>
  47. <version>5.3.5</version>
  48. </dependency>
  49. <!--apache commons日志包-->
  50. <dependency>
  51. <groupId>commons-logging</groupId>
  52. <artifactId>commons-logging</artifactId>
  53. <version>1.2</version>
  54. </dependency>
  55. <!--log4j日志包-->
  56. <dependency>
  57. <groupId>org.apache.logging.log4j</groupId>
  58. <artifactId>log4j-slf4j-impl</artifactId>
  59. <version>2.14.0</version>
  60. <scope>test</scope>
  61. </dependency>
  62. <!--lombok-->
  63. <dependency>
  64. <groupId>org.projectlombok</groupId>
  65. <artifactId>lombok</artifactId>
  66. <version>1.18.12</version>
  67. <scope>provided</scope>
  68. </dependency>
  69. <!--springtest 支持包-->
  70. <dependency>
  71. <groupId>org.springframework</groupId>
  72. <artifactId>spring-test</artifactId>
  73. <version>5.3.5</version>
  74. </dependency>
  75. <!--junit5单元测试包-->
  76. <dependency>
  77. <groupId>org.junit.jupiter</groupId>
  78. <artifactId>junit-jupiter-api</artifactId>
  79. <version>5.7.0</version>
  80. <scope>test</scope>
  81. </dependency>
  82. <!--springMVC支持包-->
  83. <dependency>
  84. <groupId>org.springframework</groupId>
  85. <artifactId>spring-web</artifactId>
  86. <version>5.3.5</version>
  87. </dependency>
  88. <dependency>
  89. <groupId>org.springframework</groupId>
  90. <artifactId>spring-webmvc</artifactId>
  91. <version>5.3.5</version>
  92. </dependency>
  93. <!--jsp-->
  94. <dependency>
  95. <groupId>javax.servlet</groupId>
  96. <artifactId>javax.servlet-api</artifactId>
  97. <version>4.0.1</version>
  98. <scope>provided</scope>
  99. </dependency>
  100. <!--servlet-->
  101. <dependency>
  102. <groupId>javax.servlet.jsp</groupId>
  103. <artifactId>javax.servlet.jsp-api</artifactId>
  104. <version>2.3.3</version>
  105. <scope>provided</scope>
  106. </dependency>
  107. <!--JSON依赖-->
  108. <dependency>
  109. <groupId>com.fasterxml.jackson.core</groupId>
  110. <artifactId>jackson-databind</artifactId>
  111. <version>2.9.1</version>
  112. </dependency>
  113. <dependency>
  114. <groupId>com.fasterxml.jackson.core</groupId>
  115. <artifactId>jackson-core</artifactId>
  116. <version>2.9.1</version>
  117. </dependency>
  118. <dependency>
  119. <groupId>com.fasterxml.jackson.core</groupId>
  120. <artifactId>jackson-annotations</artifactId>
  121. <version>2.9.1</version>
  122. </dependency>
  123. <!--mybaties的核心jar包-->
  124. <dependency>
  125. <groupId>org.mybatis</groupId>
  126. <artifactId>mybatis</artifactId>
  127. <version>3.5.3</version>
  128. </dependency>
  129. <!--spring和mybatis的整合包-->
  130. <dependency>
  131. <groupId>org.mybatis</groupId>
  132. <artifactId>mybatis-spring</artifactId>
  133. <version>2.0.3</version>
  134. </dependency>
  135. <!--日志包-->
  136. <dependency>
  137. <groupId>org.slf4j</groupId>
  138. <artifactId>slf4j-log4j12</artifactId>
  139. <version>1.6.1</version>
  140. </dependency>
  141. <!--代码生成工具-->
  142. <dependency>
  143. <groupId>org.mybatis.generator</groupId>
  144. <artifactId>mybatis-generator-core</artifactId>
  145. <version>1.3.2</version>
  146. </dependency>
  147. <!--junit-->
  148. <dependency>
  149. <groupId>junit</groupId>
  150. <artifactId>junit</artifactId>
  151. <version>4.12</version>
  152. <scope>test</scope>
  153. </dependency>

7. 准备配置文件springmvc.xml、log4j2.xml、jdbc.properties、applicationContext.xml、web.xml、generatorConfig.xml。

 generatorConfig.xml:生成mybatis相关的mapper接口和xml、实体类

  1. <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC
  2. "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  3. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  4. <generatorConfiguration>
  5. <classPathEntry
  6. location="D:\maven\repository\mysql\mysql-connector-java\8.0.22\mysql-connector-java-8.0.22.jar"/>
  7. <context id="testTables" targetRuntime="MyBatis3">
  8. <commentGenerator>
  9. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  10. <property name="suppressAllComments" value="true"/>
  11. </commentGenerator>
  12. <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
  13. <!--<jdbcConnection driverClass="${jdbc.driver}"--> <!--connectionURL="${jdbc.url}"--> <!--userId="${jdbc.username}"--> <!--password="${jdbc.password}">--> <!--</jdbcConnection>-->
  14. <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
  15. connectionURL="jdbc:mysql://127.0.0.1:3306/test?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai&amp;allowPublicKeyRetrieval=true"
  16. userId="root" password="******">
  17. </jdbcConnection>
  18. <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->
  19. <javaTypeResolver>
  20. <property name="forceBigDecimals" value="false"/>
  21. </javaTypeResolver>
  22. <!-- targetProject:生成PO类的位置 -->
  23. <javaModelGenerator targetPackage="com.ssm.bean"
  24. targetProject="F:\myTestProject\mySsmProject\src\main\java">
  25. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  26. <property name="enableSubPackages" value="false"/>
  27. <!-- 从数据库返回的值被清理前后的空格 -->
  28. <property name="trimStrings" value="true"/>
  29. </javaModelGenerator>
  30. <!-- targetProject:mapper映射文件生成的位置 -->
  31. <sqlMapGenerator targetPackage="com.ssm.mapper"
  32. targetProject="F:\myTestProject\mySsmProject\src\main\resources">
  33. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  34. <property name="enableSubPackages" value="false"/>
  35. </sqlMapGenerator>
  36. <!-- targetPackage:mapper接口生成的位置 -->
  37. <javaClientGenerator type="XMLMAPPER" targetPackage="com.ssm.mapper"
  38. targetProject="F:\myTestProject\mySsmProject\src\main\java">
  39. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  40. <property name="enableSubPackages" value="false"/>
  41. </javaClientGenerator>
  42. <!-- 指定数据库表 -->
  43. <table tableName="gameuser" domainObjectName="Gameuser"
  44. enableCountByExample="false"
  45. enableUpdateByExample="false"
  46. enableDeleteByExample="false"
  47. enableSelectByExample="false"
  48. selectByExampleQueryId="false">
  49. </table>
  50. <!-- 有些表的字段需要指定java类型
  51. <table tableName="area" domainObjectName="Area"
  52. enableCountByExample="false"
  53. enableUpdateByExample="false"
  54. enableDeleteByExample="false"
  55. enableSelectByExample="false"
  56. selectByExampleQueryId="false">
  57. </table>
  58. -->
  59. </context>
  60. </generatorConfiguration>

springmvc.xml:springMvc的核心配置文件 :

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:c="http://www.springframework.org/schema/c"
  5. xmlns:util="http://www.springframework.org/schema/util"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:aop="http://www.springframework.org/schema/aop"
  8. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
  9. xsi:schemaLocation="http://www.springframework.org/schema/beans
  10. http://www.springframework.org/schema/beans/spring-beans.xsd
  11. http://www.springframework.org/schema/util
  12. http://www.sprineframework.ore/schema/util/spring-util.xsd
  13. http://www.springframework.org/schema/context
  14. http://www.springframework.org/schema/context/spring-context.xsd
  15. http://www.springframework.org/schema/aop
  16. http://www.springframework.org/schema/aop/spring-aop.xsd
  17. http://www.springframework.org/schema/tx
  18. http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
  19. <!-- 扫描comtroller包的路径 -->
  20. <context:component-scan base-package="com.ssm"></context:component-scan>
  21. <!--开启默认配置器 配置三大组件-->
  22. <mvc:annotation-driven></mvc:annotation-driven>
  23. <!--配置视图解析器-->
  24. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  25. <property name="prefix" value="/jsp/"></property>
  26. <property name="suffix" value=".jsp"></property>
  27. </bean>
  28. <!--配置静态资源放行-->
  29. <mvc:default-servlet-handler/>
  30. </beans>

log4j2.xml: spring 使用此配置文件打印日志:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Configuration status="INFO">
  3. <Appenders>
  4. <Console name="Console" target="SYSTEM_OUT">
  5. <PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n"/>
  6. </Console>
  7. </Appenders>
  8. <Loggers>
  9. <Root level="info">
  10. <AppenderRef ref="Console"/>
  11. </Root>
  12. </Loggers>
  13. </Configuration>

 jdbc.properties:数据库连接信息配置

  1. ## key=value
  2. driver=com.mysql.cj.jdbc.Driver
  3. url=jdbc:mysql://127.0.0.1:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
  4. username=root
  5. password=12346

applicationContext.xml: spring的核心配置文件

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:c="http://www.springframework.org/schema/c"
  5. xmlns:util="http://www.springframework.org/schema/util"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:aop="http://www.springframework.org/schema/aop"
  8. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
  9. xsi:schemaLocation="http://www.springframework.org/schema/beans
  10. http://www.springframework.org/schema/beans/spring-beans.xsd
  11. http://www.springframework.org/schema/util
  12. http://www.sprineframework.ore/schema/util/spring-util.xsd
  13. http://www.springframework.org/schema/context
  14. http://www.springframework.org/schema/context/spring-context.xsd
  15. http://www.springframework.org/schema/aop
  16. http://www.springframework.org/schema/aop/spring-aop.xsd
  17. http://www.springframework.org/schema/tx
  18. http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
  19. <!--加载配置文件properties-->
  20. <context:property-placeholder location="classpath:jdbc.properties"/>
  21. <!--包扫描 扫描service层-->
  22. <context:component-scan base-package="com.ssm.service"/>
  23. <!--配置数据源 德鲁伊数据库连接池 读取properties配置文件中的信息-->
  24. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
  25. <!--读取properties配置文件中的信息-->
  26. <property name="driverClassName" value="${driver}"></property>
  27. <property name="url" value="${url}"></property>
  28. <property name="username" value="${username}"></property>
  29. <property name="password" value="${password}"></property>
  30. </bean>
  31. <!--将sqlsessionfactory对象交由spring创建和管理-->
  32. <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
  33. <!--配置数据源-->
  34. <property name="dataSource" ref="dataSource"></property>
  35. <!--配置实体类扫描包路径-->
  36. <property name="typeAliasesPackage" value="com.lc.ssm.bean"></property>
  37. </bean>
  38. <!--将mapper交由spring创建和管理 生成mapper对象放入容器-->
  39. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  40. <!--注入sqlsessionfactory-->
  41. <property name="sqlSessionFactoryBeanName" value="factory"></property>
  42. <!--扫描所有的mapper接口和映射文件-->
  43. <property name="basePackage" value="com.lc.ssm.mapper"></property>
  44. </bean>
  45. <!--配置事务管理器 -->
  46. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  47. <property name="dataSource" ref="dataSource"></property>
  48. </bean>
  49. <!--开启事务注解-->
  50. <tx:annotation-driven transaction-manager="transactionManager"/>
  51. </beans>

 Web.xml:配置基础信息:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  5. version="4.0">
  6. <!--配置dispacherServlet-->
  7. <servlet>
  8. <servlet-name>dispatcherServlet</servlet-name>
  9. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  10. <init-param>
  11. <param-name>contextConfigLocation</param-name>
  12. <param-value>classpath:springmvc.xml</param-value>
  13. </init-param>
  14. <load-on-startup>1</load-on-startup>
  15. </servlet>
  16. <servlet-mapping>
  17. <servlet-name>dispatcherServlet</servlet-name>
  18. <url-pattern>/</url-pattern>
  19. </servlet-mapping>
  20. <!--配置SpringMVC的编码过滤器 解决post请求乱码-->
  21. <filter>
  22. <filter-name>CharacterEncodingFilter</filter-name>
  23. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  24. <init-param>
  25. <param-name>encoding</param-name>
  26. <param-value>UTF-8</param-value>
  27. </init-param>
  28. <init-param>
  29. <param-name>forceEncoding</param-name>
  30. <param-value>true</param-value>
  31. </init-param>
  32. </filter>
  33. <filter-mapping>
  34. <filter-name>CharacterEncodingFilter</filter-name>
  35. <url-pattern>/*</url-pattern>
  36. </filter-mapping>
  37. <!--配置spring核心容器 配置spring 核心配置文件的位置 -->
  38. <context-param>
  39. <param-name>contextConfigLocation</param-name>
  40. <param-value>classpath:applicationContext.xml</param-value>
  41. </context-param>
  42. <!--监听servletContext对象 在创建servletContext对象时创建spring容器放入其中-->
  43. <listener>
  44. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  45. </listener>
  46. </web-app>

配置log4j.properties,生成mapper时需要使用此打印日志:

  1. #定义全局日志级别调试阶段推荐debug
  2. log4j.rootLogger=debug,stdout
  3. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  4. log4j.appender.stdout.Target=System.err
  5. log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
  6. log4j.appender.logfile=org.apache.log4j.FileAppender
  7. log4j.appender.logfile.File=d:/msb.log
  8. log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
  9. log4j.appender.logfile.layout.ConversionPattern=%d(yyyy-MM-dd HH:mm:ss)%1 %F %p %m%n

在test目录下新增测试类,运行时用于生成mybatis相关的代码,代码如下:

  1. package com.ssm.test;
  2. import org.mybatis.generator.api.MyBatisGenerator;
  3. import org.mybatis.generator.config.Configuration;
  4. import org.mybatis.generator.config.xml.ConfigurationParser;
  5. import org.mybatis.generator.internal.DefaultShellCallback;
  6. import java.io.File;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. /**
  10. * @{NAME}
  11. * @Description TODO
  12. * @Author luocong
  13. * @Date
  14. * @Version 1.0
  15. **/
  16. public class GeneratorCode {
  17. public void generator() throws Exception {
  18. List<String> warnings = new ArrayList<String>();
  19. boolean overwrite = true;
  20. File configFile = new File("F:\\ideagit\\springall\\mybatisTest01\\target\\classes\\generatorConfig.xml");
  21. ConfigurationParser cp = new ConfigurationParser(warnings);
  22. Configuration config = cp.parseConfiguration(configFile);
  23. DefaultShellCallback callback = new DefaultShellCallback(overwrite);
  24. MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
  25. callback,warnings);
  26. myBatisGenerator.generate(null);
  27. }
  28. public static void main(String[] args) {
  29. GeneratorCode generatorSqlmap = new GeneratorCode();
  30. try {
  31. generatorSqlmap.generator();
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }

 执行mian类,生成mapperxml和mapper接口以及mapper实体类。

 至此,ssm开发环境搭建完毕。

开发前端项目代码

App.vue:

  1. <template>
  2. <div id="app">
  3. <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
  4. <!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->
  5. <tableInfo/>
  6. </div>
  7. </template>
  8. <script>
  9. // import HelloWorld from './components/HelloWorld.vue'
  10. import tableInfo from './components/tableInfo.vue'
  11. export default {
  12. name: 'App',
  13. components: {
  14. // HelloWorld
  15. tableInfo
  16. }
  17. }
  18. </script>
  19. <style>
  20. #app {
  21. font-family: Avenir, Helvetica, Arial, sans-serif;
  22. -webkit-font-smoothing: antialiased;
  23. -moz-osx-font-smoothing: grayscale;
  24. text-align: center;
  25. color: #2c3e50;
  26. margin-top: 60px;
  27. }
  28. </style>

tableInfoVue:

  1. <template>
  2. <div>
  3. <div>
  4. <el-form ref="elForm" :model="formQueryData" :rules="rules" size="small" label-width="100px"
  5. label-position="left">
  6. <el-form-item label="用户姓名" prop="query_usrNm">
  7. <el-input v-model="formQueryData.query_usrNm" placeholder="请输入用户姓名" :maxlength="20" show-word-limit
  8. clearable prefix-icon='el-icon-s-custom' :style="{width: '100%'}"></el-input>
  9. </el-form-item>
  10. <el-form-item label="用户名称" prop="query_usrLoginNm">
  11. <el-input v-model="formQueryData.query_usrLoginNm" placeholder="请输入用户名称" :maxlength="20"
  12. show-word-limit clearable prefix-icon='el-icon-user' :style="{width: '100%'}"></el-input>
  13. </el-form-item>
  14. <el-form-item label="身份证号" prop="query_usrCardNum">
  15. <el-input v-model="formQueryData.query_usrCardNum" placeholder="请输入身份证号" :maxlength="18"
  16. show-word-limit clearable prefix-icon='el-icon-postcard' :style="{width: '100%'}"></el-input>
  17. </el-form-item>
  18. <el-form-item label="用户地址" prop="query_usrPro">
  19. <el-select v-model="formQueryData.query_usrPro" placeholder="请选择用户地址" clearable
  20. :style="{width: '100%'}">
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="生日" prop="query_usrBirDate">
  24. <el-date-picker v-model="formQueryData.query_usrBirDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  25. :style="{width: '100%'}" placeholder="请选择生日" clearable></el-date-picker>
  26. </el-form-item>
  27. <el-form-item label="爱好" prop="query_usrHobby">
  28. <el-checkbox-group v-model="formQueryData.query_usrHobby" :min="1" size="medium">
  29. <el-checkbox-button v-for="(item, index) in query_usrHobbyOptions" :key="index" :label="item.value"
  30. :disabled="item.disabled" border>{{item.label}}</el-checkbox-button>
  31. </el-checkbox-group>
  32. </el-form-item>
  33. <el-form-item label="用户简介" prop="query_usrDetail">
  34. <el-input v-model="formQueryData.query_usrDetail" type="textarea" placeholder="请输入用户简介"
  35. :maxlength="50" show-word-limit :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}">
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item size="large">
  39. <el-button type="primary" @click="submitForm">提交</el-button>
  40. <el-button @click="resetForm">重置</el-button>
  41. </el-form-item>
  42. </el-form>
  43. </div>
  44. <el-button style="margin-left: 20px;" @click="addUser()">新增</el-button>
  45. <el-table
  46. :data="tableData"
  47. border
  48. style="width: 100%">
  49. <el-table-column
  50. prop="usrFileUrl"
  51. label="头像"
  52. width="200">
  53. <template v-slot:default="scope">
  54. <el-image :src="scope.row.usrFileUrl"/>
  55. <el-link :href="scope.row.usrFileUrl">查看详情</el-link>
  56. </template>
  57. </el-table-column>
  58. <el-table-column
  59. prop="usrNm"
  60. label="用户姓名"
  61. width="200">
  62. </el-table-column>
  63. <el-table-column
  64. prop="usrCardNum"
  65. label="身份证号"
  66. width="200">
  67. </el-table-column>
  68. <el-table-column
  69. prop="usrAddr"
  70. label="通信地址"
  71. width="200">
  72. </el-table-column>
  73. <el-table-column
  74. prop="usrBirDate"
  75. label="出生日期"
  76. width="200">
  77. </el-table-column>
  78. <el-table-column
  79. prop="usrHobby"
  80. label="爱好"
  81. width="200">
  82. </el-table-column>
  83. <el-table-column
  84. prop="usrDetail"
  85. label="个人简介"
  86. width="300">
  87. </el-table-column>
  88. <el-table-column
  89. fixed="right"
  90. label="操作"
  91. width="200">
  92. <template slot-scope="scope">
  93. <template>
  94. <el-popconfirm title="这是一段内容确定删除吗?" @confirm="handleClick(scope.row)" >
  95. <el-button slot="reference">删除</el-button>
  96. </el-popconfirm>
  97. </template>
  98. <el-button style="margin-left: 20px;" @click="upuser(scope.row)">修改</el-button>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <div class="block">
  103. <span class="demonstration"></span>
  104. <el-pagination
  105. @size-change="handleSizeChange"
  106. @current-change="handleCurrentChange"
  107. :current-page="currentPage"
  108. :page-sizes="pageSizes"
  109. :page-size="PageSize"
  110. layout="total, sizes, prev, pager, next, jumper"
  111. :total="totalCount">
  112. </el-pagination>
  113. </div>
  114. <div>
  115. <el-dialog title="用户信息新增" :visible.sync="addialogFormVisible" >
  116. <el-form ref="elForm" :model="formAddData.usrFileUrl" :rules="rules" size="medium" label-width="100px">
  117. <el-form-item label="点击上传" prop="usrImg" required>
  118. <el-upload
  119. class="avatar-uploader"
  120. action="http://localhost:8080/api/uploadFile"
  121. :show-file-list="false"
  122. :on-success="handleAvatarSuccess"
  123. :before-upload="beforeAvatarUpload">
  124. <img v-if="imageUrl" :src="imageUrl" class="avatar">
  125. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  126. </el-upload>
  127. </el-form-item>
  128. <el-form-item label="用户名称" prop="usrLoginNm">
  129. <el-input v-model="formAddData.usrLoginNm" placeholder="请输入用户名称" :maxlength="20" show-word-limit
  130. clearable prefix-icon='el-icon-user' :style="{width: '100%'}"></el-input>
  131. </el-form-item>
  132. <el-form-item label="用户密码" prop="usrLoginPwd">
  133. <el-input v-model="formAddData.usrLoginPwd" placeholder="请输入用户密码" :maxlength="12" show-word-limit
  134. clearable prefix-icon='el-icon-star-on' show-password :style="{width: '100%'}"></el-input>
  135. </el-form-item>
  136. <el-form-item label="确认密码" prop="usrLoginPwd1">
  137. <el-input v-model="formAddData.usrLoginPwd1" placeholder="请再次确认密码" :maxlength="12" show-word-limit
  138. clearable prefix-icon='el-icon-star-on' show-password :style="{width: '100%'}"></el-input>
  139. </el-form-item>
  140. <el-form-item label="用户姓名" prop="usrNm">
  141. <el-input v-model="formAddData.usrNm" placeholder="请输入用户姓名" :maxlength="20" show-word-limit clearable
  142. prefix-icon='el-icon-s-custom' :style="{width: '100%'}"></el-input>
  143. </el-form-item>
  144. <el-form-item label="身份证号" prop="usrCardNum">
  145. <el-input v-model="formAddData.usrCardNum" placeholder="请输入身份证号" :maxlength="18" show-word-limit
  146. clearable prefix-icon='el-icon-postcard' :style="{width: '100%'}"></el-input>
  147. </el-form-item>
  148. <el-form-item label="所属省份" prop="usrPro">
  149. <el-select v-model="formAddData.usrPro" placeholder="请选择所属省份" clearable :style="{width: '100%'}" @change="changeAddCitySelect($event)">
  150. <el-option
  151. v-for="(item,index) in usrAddProList"
  152. :key="index"
  153. :label="item.areaname"
  154. :value="item.areaid">
  155. </el-option>
  156. </el-select>
  157. </el-form-item>
  158. <el-form-item label="所属市" prop="usrCity">
  159. <el-select v-model="formAddData.usrCity" placeholder="请选择所属市" filterable clearable
  160. :style="{width: '100%'}" @change="changeAddFaddrSelect($event)" >
  161. <el-option
  162. v-for="(item,index) in usrAddCityList"
  163. :key="index"
  164. :label="item.areaname"
  165. :value="item.areaid">
  166. </el-option>
  167. </el-select>
  168. </el-form-item>
  169. <el-form-item label="所属县/区" prop="usrFaddr">
  170. <el-select v-model="formAddData.usrFaddr" placeholder="请选择所属县/区" filterable clearable
  171. :style="{width: '100%'}">
  172. <el-option
  173. v-for="(item,index) in usrAddFaddrList"
  174. :key="index"
  175. :label="item.areaname"
  176. :value="item.areaid">
  177. </el-option>
  178. </el-select>
  179. </el-form-item>
  180. <el-form-item label="生日" prop="usrBirDate">
  181. <el-date-picker v-model="formAddData.usrBirDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  182. :style="{width: '100%'}" placeholder="请选择生日" clearable></el-date-picker>
  183. </el-form-item>
  184. <el-form-item label="爱好" prop="usrHobby">
  185. <el-checkbox-group v-model="formAddData.usrHobby" :min="1" size="medium">
  186. <el-checkbox-button v-for="(item, index) in usrHobbyOptions" :key="index" :label="item.value"
  187. :disabled="item.disabled" border>{{item.label}}</el-checkbox-button>
  188. </el-checkbox-group>
  189. </el-form-item>
  190. <el-form-item label="用户简介" prop="usrDetail">
  191. <el-input v-model="formAddData.usrDetail" type="textarea" placeholder="请输入用户简介" :maxlength="50"
  192. show-word-limit :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
  193. </el-form-item>
  194. </el-form>
  195. <div slot="footer" class="dialog-footer">
  196. <el-button @click="addialogFormVisible = false">取 消</el-button>
  197. <el-button type="primary" @click="addSubmit">确 定</el-button>
  198. </div>
  199. </el-dialog>
  200. </div>
  201. <div>
  202. <el-dialog title="用户信息修改" :visible.sync="updialogFormVisible" >
  203. <el-form ref="elForm" :model="formData.usrFileUrl" :rules="rules" size="medium" label-width="100px">
  204. <el-form-item label="点击上传" prop="usrImg" required>
  205. <el-upload
  206. class="avatar-uploader"
  207. action="http://localhost:8080/api/uploadFile"
  208. :show-file-list="false"
  209. :on-success="handleAvatarSuccess"
  210. :before-upload="beforeAvatarUpload">
  211. <img v-if="imageUrl" :src="imageUrl" class="avatar">
  212. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  213. </el-upload>
  214. </el-form-item>
  215. <el-form-item label="用户名称" prop="usrLoginNm">
  216. <el-input v-model="formData.usrLoginNm" placeholder="请输入用户名称" :maxlength="20" show-word-limit
  217. clearable prefix-icon='el-icon-user' :style="{width: '100%'}"></el-input>
  218. </el-form-item>
  219. <el-form-item label="用户密码" prop="usrLoginPwd">
  220. <el-input v-model="formData.usrLoginPwd" placeholder="请输入用户密码" :maxlength="12" show-word-limit
  221. clearable prefix-icon='el-icon-star-on' show-password :style="{width: '100%'}"></el-input>
  222. </el-form-item>
  223. <el-form-item label="确认密码" prop="usrLoginPwd1">
  224. <el-input v-model="formData.usrLoginPwd1" placeholder="请再次确认密码" :maxlength="12" show-word-limit
  225. clearable prefix-icon='el-icon-star-on' show-password :style="{width: '100%'}"></el-input>
  226. </el-form-item>
  227. <el-form-item label="用户姓名" prop="usrNm">
  228. <el-input v-model="formData.usrNm" placeholder="请输入用户姓名" :maxlength="20" show-word-limit clearable
  229. prefix-icon='el-icon-s-custom' :style="{width: '100%'}"></el-input>
  230. </el-form-item>
  231. <el-form-item label="身份证号" prop="usrCardNum">
  232. <el-input v-model="formData.usrCardNum" placeholder="请输入身份证号" :maxlength="18" show-word-limit
  233. clearable prefix-icon='el-icon-postcard' :style="{width: '100%'}"></el-input>
  234. </el-form-item>
  235. <el-form-item label="所属省份" prop="usrPro">
  236. <el-select v-model="formData.usrPro" placeholder="请选择所属省份" clearable :style="{width: '100%'}" @change="changeCitySelect($event)">
  237. <el-option
  238. v-for="(item,index) in usrProList"
  239. :key="index"
  240. :label="item.areaname"
  241. :value="item.areaid">
  242. </el-option>
  243. </el-select>
  244. </el-form-item>
  245. <el-form-item label="所属市" prop="usrCity">
  246. <el-select v-model="formData.usrCity" placeholder="请选择所属市" filterable clearable
  247. :style="{width: '100%'}" @change="changeFaddrSelect($event)" >
  248. <el-option
  249. v-for="(item,index) in usrCityList"
  250. :key="index"
  251. :label="item.areaname"
  252. :value="item.areaid">
  253. </el-option>
  254. </el-select>
  255. </el-form-item>
  256. <el-form-item label="所属县/区" prop="usrFaddr">
  257. <el-select v-model="formData.usrFaddr" placeholder="请选择所属县/区" filterable clearable
  258. :style="{width: '100%'}">
  259. <el-option
  260. v-for="(item,index) in usrFaddrList"
  261. :key="index"
  262. :label="item.areaname"
  263. :value="item.areaid">
  264. </el-option>
  265. </el-select>
  266. </el-form-item>
  267. <el-form-item label="生日" prop="usrBirDate">
  268. <el-date-picker v-model="formData.usrBirDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  269. :style="{width: '100%'}" placeholder="请选择生日" clearable></el-date-picker>
  270. </el-form-item>
  271. <el-form-item label="爱好" prop="usrHobby">
  272. <el-checkbox-group v-model="formData.usrHobby" :min="1" size="medium">
  273. <el-checkbox-button v-for="(item, index) in usrHobbyOptions" :key="index" :label="item.value"
  274. :disabled="item.disabled" border>{{item.label}}</el-checkbox-button>
  275. </el-checkbox-group>
  276. </el-form-item>
  277. <el-form-item label="用户简介" prop="usrDetail">
  278. <el-input v-model="formData.usrDetail" type="textarea" placeholder="请输入用户简介" :maxlength="50"
  279. show-word-limit :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
  280. </el-form-item>
  281. </el-form>
  282. <div slot="footer" class="dialog-footer">
  283. <el-button @click="updialogFormVisible = false">取 消</el-button>
  284. <el-button type="primary" @click="uponSubmit">确 定</el-button>
  285. </div>
  286. </el-dialog>
  287. </div>
  288. </div>
  289. </template>
  290. <script>
  291. export default {
  292. name:'tableInfo',
  293. inheritAttrs: false,
  294. components:{
  295. },
  296. data() {
  297. return {
  298. addialogFormVisible:false,
  299. imageUrl: '',
  300. usrAddProList:[],
  301. usrAddCityList:[],
  302. usrAddFaddrList:[],
  303. usrProList:[],
  304. usrCityList:[],
  305. usrFaddrList:[],
  306. tableData: [{
  307. usrId:'',
  308. usrLoginNm:'',
  309. usrLoginPwd:'',
  310. usrNm:'',
  311. usrCardNum:'',
  312. usrAddr:'',
  313. usrBirDate:null,
  314. usrHobby:[],
  315. usrDetail:'',
  316. usrFileUrl:''
  317. }],
  318. fits: [''],//图片展示的属性
  319. // 默认显示第几页
  320. currentPage:1,
  321. // 总条数,根据接口获取数据长度(注意:这里不能为空)
  322. totalCount:1,
  323. // 个数选择器(可修改)
  324. pageSizes:[10,20,30,40,50,100],
  325. // 默认每页显示的条数(可修改)
  326. PageSize:10,
  327. updialogFormVisible:false,
  328. formQueryData: {
  329. query_usrNm: '',
  330. query_usrLoginNm: "",
  331. query_usrCardNum: '',
  332. query_usrPro: '',
  333. query_usrBirDate: null,
  334. query_usrHobby: [],
  335. query_usrDetail: ''
  336. },
  337. formData: {
  338. usrImg: null,
  339. usrLoginNm: "",
  340. usrLoginPwd: undefined,
  341. usrLoginPwd1: undefined,
  342. usrNm: undefined,
  343. usrCardNum: undefined,
  344. usrPro: undefined,
  345. usrCity: undefined,
  346. usrFaddr: undefined,
  347. usrBirDate: null,
  348. usrHobby: [],
  349. usrDetail: undefined,
  350. },
  351. formAddData: {
  352. usrImg: null,
  353. usrLoginNm: "",
  354. usrLoginPwd: undefined,
  355. usrLoginPwd1: undefined,
  356. usrNm: undefined,
  357. usrCardNum: undefined,
  358. usrPro: undefined,
  359. usrCity: undefined,
  360. usrFaddr: undefined,
  361. usrBirDate: null,
  362. usrHobby: [],
  363. usrDetail: undefined,
  364. },
  365. //表单校验
  366. rules: {
  367. query_usrNm: [],
  368. query_usrLoginNm: [{
  369. pattern: /^[a-zA-Z0-9_-]{4,16}$/,
  370. message: '用户名必须由字母、数字、下划线或减号组成!',
  371. trigger: 'blur'
  372. }],
  373. query_usrCardNum: [{
  374. pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  375. message: '请输入正确格式的身份证号码!',
  376. trigger: 'blur'
  377. }],
  378. query_usrPro: [],
  379. query_usrBirDate: [],
  380. query_usrHobby: [],
  381. query_usrDetail: [],
  382. },
  383. query_usrHobbyOptions: [{
  384. "label": "唱歌",
  385. "value": 1
  386. }, {
  387. "label": "游泳",
  388. "value": 2
  389. }, {
  390. "label": "看书",
  391. "value": 3
  392. }, {
  393. "label": "打游戏",
  394. "value": 4
  395. }, {
  396. "label": "party",
  397. "value": 5
  398. }],
  399. usrLoginNm: [{
  400. required: true,
  401. message: '请输入用户名称',
  402. trigger: 'blur'
  403. }, {
  404. pattern: /^[a-zA-Z0-9_-]{4,16}$/,
  405. message: '用户名必须由字母、数字、下划线或减号组成!',
  406. trigger: 'blur'
  407. }],
  408. usrLoginPwd: [{
  409. required: true,
  410. message: '请输入用户密码',
  411. trigger: 'blur'
  412. }, {
  413. pattern: /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/,
  414. message: '密码长度必须满足6位且由大写字母、小写字母、数字、和特殊字符组成!',
  415. trigger: 'blur'
  416. }],
  417. usrLoginPwd1: [{
  418. required: true,
  419. message: '请再次确认密码',
  420. trigger: 'blur'
  421. }, {
  422. pattern: /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/,
  423. message: '密码长度必须满足6位且由大写字母、小写字母、数字、和特殊字符组成!',
  424. trigger: 'blur'
  425. }],
  426. usrNm: [{
  427. required: true,
  428. message: '请输入用户姓名',
  429. trigger: 'blur'
  430. }],
  431. usrCardNum: [{
  432. required: true,
  433. message: '请输入身份证号',
  434. trigger: 'blur'
  435. }, {
  436. pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  437. message: '请输入正确格式的身份证号码!',
  438. trigger: 'blur'
  439. }],
  440. usrPro: [{
  441. required: true,
  442. message: '请选择所属省份',
  443. trigger: 'change'
  444. }],
  445. usrCity: [{
  446. required: true,
  447. message: '请选择所属市',
  448. trigger: 'change'
  449. }],
  450. usrFaddr: [{
  451. required: true,
  452. message: '请选择所属县/区',
  453. trigger: 'change'
  454. }],
  455. usrBirDate: [{
  456. required: true,
  457. message: '请选择生日',
  458. trigger: 'change'
  459. }],
  460. usrHobby: [],
  461. usrDetail: [{
  462. required: true,
  463. message: '请输入用户简介',
  464. trigger: 'blur'
  465. }],
  466. usrImgAction: 'http://localhost:8080/api/uploadFile',
  467. usrImgfileList: [],
  468. usrHobbyOptions: [{
  469. "label": "唱歌",
  470. "value": 1
  471. }, {
  472. "label": "游泳",
  473. "value": 2
  474. }, {
  475. "label": "看书",
  476. "value": 3
  477. }, {
  478. "label": "打游戏",
  479. "value": 4
  480. }, {
  481. "label": "party",
  482. "value": 5
  483. }]
  484. }
  485. },
  486. methods:{
  487. addSubmit(){
  488. var fileurl=''
  489. if(this.formAddData.usrFileUrl==undefined){
  490. fileurl=''
  491. }else{
  492. fileurl=this.formAddData.usrFileUrl
  493. }
  494. //获取formAddData的数据 修改用户信息
  495. this.$http.get('/addGameUserInfo', {params:{
  496. usrLoginNm:this.formAddData.usrLoginNm,
  497. usrLoginPwd:this.formAddData.usrLoginPwd,
  498. usrNm:this.formAddData.usrNm,
  499. usrCardNum:this.formAddData.usrCardNum,
  500. usrAddr:this.formAddData.usrPro+"-"+this.formAddData.usrCity+"-"+this.formAddData.usrFaddr,
  501. usrBirDate:this.formAddData.usrBirDate,
  502. usrHobby:this.formAddData.usrHobby.join(","),
  503. usrDetail:this.formAddData.usrDetail,
  504. usrFileUrl:fileurl
  505. }}).then((response) =>{
  506. if(response.data.msg=='success'){
  507. this.addialogFormVisible=false;
  508. this.getTableList()
  509. }
  510. }).catch((error) =>{
  511. alert("error"+error)
  512. });
  513. },
  514. addUser(){
  515. this.addialogFormVisible=true;
  516. //调用接口获取省份信息
  517. this.getAddProList(0,0)
  518. },
  519. changeFaddrSelect(event){
  520. this.usrFaddrList=[]
  521. this.formData.usrFaddr=''
  522. console.log("选择县区",event)
  523. //调用查询市信息的接口查询市信息 为县区列表赋值
  524. this.$http.get('/getAreaInfo', {params:{
  525. parentid:event
  526. }}).then((response) =>{
  527. this.usrFaddrList=response.data
  528. }).catch((error) => {
  529. console.log(error.getMessage);
  530. });
  531. },
  532. changeCitySelect(event){
  533. this.usrCityList=[]
  534. this.formData.usrCity=''
  535. this.formData.usrFaddr=''
  536. console.log("选择市1",event)
  537. //调用查询市信息的接口查询市信息 为市列表赋值
  538. this.$http.get('/getAreaInfo', {params:{
  539. parentid:event
  540. }}).then((response) =>{
  541. this.usrCityList=response.data
  542. }).catch((error) => {
  543. console.log(error.getMessage);
  544. });
  545. },
  546. getProList(parentid,listInfo){//获取省份信息
  547. this.$http.get('/getAreaInfo', {params:{
  548. parentid:parentid
  549. }}).then((response) =>{
  550. console.log(response.data.areaList)
  551. if(listInfo==0){//0-查询省信息
  552. this.usrProList=response.data
  553. }else if(listInfo==1){//1-查询市信息
  554. this.usrCityList=response.data
  555. }else{//2-查询县/区信息
  556. this.usrFaddrList=response.data
  557. }
  558. }).catch((error) => {
  559. console.log(error.getMessage);
  560. });
  561. },
  562. changeAddFaddrSelect(event){
  563. this.usrAddFaddrList=[]
  564. this.formAddData.usrFaddr=''
  565. console.log("选择县区",event)
  566. //调用查询市信息的接口查询市信息 为县区列表赋值
  567. this.$http.get('/getAreaInfo', {params:{
  568. parentid:event
  569. }}).then((response) =>{
  570. this.usrAddFaddrList=response.data
  571. }).catch((error) => {
  572. console.log(error.getMessage);
  573. });
  574. },
  575. changeAddCitySelect(event){
  576. this.usrAddCityList=[]
  577. this.formAddData.usrCity=''
  578. this.formAddData.usrFaddr=''
  579. console.log("选择市1",event)
  580. //调用查询市信息的接口查询市信息 为市列表赋值
  581. this.$http.get('/getAreaInfo', {params:{
  582. parentid:event
  583. }}).then((response) =>{
  584. this.usrAddCityList=response.data
  585. }).catch((error) => {
  586. console.log(error.getMessage);
  587. });
  588. },
  589. getAddProList(parentid,listInfo){//获取省份信息
  590. this.$http.get('/getAreaInfo', {params:{
  591. parentid:parentid
  592. }}).then((response) =>{
  593. console.log(response.data.areaList)
  594. if(listInfo==0){//0-查询省信息
  595. this.usrAddProList=response.data
  596. }else if(listInfo==1){//1-查询市信息
  597. this.usrAddCityList=response.data
  598. }else{//2-查询县/区信息
  599. this.usrAddFaddrList=response.data
  600. }
  601. }).catch((error) => {
  602. console.log(error.getMessage);
  603. });
  604. },
  605. handleClick(row) {//传入选中这一行的数据,可以进行操作
  606. this.$http.get('/delGameUserInfoById', {params:{
  607. usrId:row.usrId
  608. }}).then((response) =>{
  609. if(response.data.msg=='success'){
  610. this.getTableList()
  611. }
  612. }).catch((error) => {
  613. console.log(error.getMessage);
  614. });
  615. },
  616. getTableList(){
  617. console.log("this.formQueryData: "+this.formQueryData.query_usrHobby.join(","))
  618. this.$http.get('/getAllGameUserList', {params:{
  619. currentPage:this.currentPage,
  620. pageSize:this.PageSize,
  621. recordCount:this.totalCount,
  622. usrLoginNm:this.formQueryData.query_usrLoginNm,
  623. usrNm:this.formQueryData.query_usrNm,
  624. usrCardNum:this.formQueryData.query_usrCardNum,
  625. usrAddr:this.formQueryData.query_usrPro,
  626. usrBirDate:this.formQueryData.query_usrBirDate,
  627. usrHobby:this.formQueryData.query_usrHobby.join(","),
  628. usrDetail:this.formQueryData.query_usrDetail
  629. }}).then((response) =>{
  630. this.totalCount=response.data.totalCount
  631. this.currentPage=response.data.currentPage
  632. this.PageSize=response.data.pageSize
  633. this.tableData=response.data.recordList
  634. }).catch((error) =>{
  635. alert("error"+error)
  636. });
  637. },
  638. // 分页
  639. // 每页显示的条数
  640. handleSizeChange(val) {
  641. // 改变每页显示的条数
  642. this.PageSize=val
  643. // 注意:在改变每页显示的条数时,要将页码显示到第一页
  644. this.currentPage=1
  645. //改变条数时触发查询
  646. this.getTableList()
  647. },
  648. // 显示第几页
  649. handleCurrentChange(val) {
  650. // 改变默认的页数
  651. this.currentPage=val
  652. //改变页数是触发查询
  653. this.getTableList()
  654. },
  655. submitForm() {
  656. this.$refs['elForm'].validate(valid => {
  657. if (!valid) return
  658. // TODO 提交表单触发查询
  659. this.getTableList()
  660. })
  661. },
  662. resetForm() {
  663. this.$refs['elForm'].resetFields()
  664. },
  665. onOpen() {},
  666. onClose() {
  667. this.$refs['elForm'].resetFields()
  668. },
  669. close() {
  670. this.$emit('update:visible', false)
  671. },
  672. handelConfirm() {
  673. this.$refs['elForm'].validate(valid => {
  674. if (!valid) return
  675. this.close()
  676. })
  677. },
  678. handleAvatarSuccess(res, file) {
  679. this.imageUrl = URL.createObjectURL(file.raw);
  680. this.formData.usrFileUrl=res.fileUrl
  681. this.formAddData.usrFileUrl=res.fileUrl
  682. console.log("imageUrl: "+this.imageUrl);
  683. },
  684. beforeAvatarUpload(file) {
  685. const isJPG = file.type === 'image/jpeg';
  686. const isLt2M = file.size / 1024 / 1024 < 2;
  687. if (!isJPG) {
  688. this.$message.error('上传头像图片只能是 JPG 格式!');
  689. }
  690. if (!isLt2M) {
  691. this.$message.error('上传头像图片大小不能超过 2MB!');
  692. }
  693. return isJPG && isLt2M;
  694. },
  695. upuser(row){
  696. this.updialogFormVisible = true
  697. //使用map将字符串数组转化为数字数组 用于checkBox回显数据
  698. var arr=row.usrHobbys.split(',')
  699. arr=arr.map(Number)
  700. console.log("arr "+arr)
  701. //将用户信息回显在form表单上
  702. const userinfo={
  703. usrId:row.usrId,
  704. usrLoginNm:row.usrLoginNm,
  705. usrLoginPwd:row.usrLoginPwd,
  706. usrLoginPwd1:row.usrLoginPwd,
  707. usrNm:row.usrNm,
  708. usrCardNum:row.usrCardNum,
  709. usrPro:row.usrAddr.split("-")[0],
  710. usrCity:row.usrAddr.split("-")[1],
  711. usrFaddr:row.usrAddr.split("-")[2],
  712. usrBirDate:row.usrBirDate,
  713. usrHobby:arr,
  714. usrDetail:row.usrDetail
  715. }
  716. this.formData=userinfo
  717. //调用接口获取省份信息
  718. this.getProList(0,0)
  719. },
  720. uponSubmit(){
  721. var fileurl=''
  722. if(this.formData.usrFileUrl==undefined||this.formData.usrFileUrl==''){
  723. fileurl=''
  724. }else{
  725. fileurl=this.formData.usrFileUrl
  726. }
  727. //获取formData的数据 修改用户信息
  728. this.$http.get('/updateGameUserInfo', {params:{
  729. usrId:this.formData.usrId,
  730. usrLoginNm:this.formData.usrLoginNm,
  731. usrLoginPwd:this.formData.usrLoginPwd,
  732. usrNm:this.formData.usrNm,
  733. usrCardNum:this.formData.usrCardNum,
  734. usrAddr:this.formData.usrPro+"-"+this.formData.usrCity+"-"+this.formData.usrFaddr,
  735. usrBirDate:this.formData.usrBirDate,
  736. usrHobby:this.formData.usrHobby.join(","),
  737. usrDetail:this.formData.usrDetail,
  738. usrFileUrl:fileurl
  739. }}).then((response) =>{
  740. if(response.data.msg=='success'){
  741. this.updialogFormVisible=false;
  742. this.getTableList()
  743. }
  744. }).catch((error) =>{
  745. alert("error"+error)
  746. });
  747. },
  748. handleChange (value) {
  749. console.log(value)
  750. }
  751. },
  752. mounted(){
  753. this.getTableList()
  754. }
  755. }
  756. </script>
  757. <style>
  758. .el-upload__tip {
  759. line-height: 1.2;
  760. }
  761. .avatar-uploader .el-upload {
  762. border: 1px dashed #d9d9d9;
  763. border-radius: 6px;
  764. cursor: pointer;
  765. position: relative;
  766. overflow: hidden;
  767. }
  768. .avatar-uploader .el-upload:hover {
  769. border-color: #409EFF;
  770. }
  771. .avatar-uploader-icon {
  772. font-size: 28px;
  773. color: #8c939d;
  774. width: 178px;
  775. height: 178px;
  776. line-height: 178px;
  777. text-align: center;
  778. }
  779. .avatar {
  780. width: 178px;
  781. height: 178px;
  782. display: block;
  783. }
  784. </style>

开发后端项目代码

后端项目目录结构如下:

源码下载地址:

链接:https://pan.baidu.com/s/163wHTpcdLdOfCUSg1PqMgg?pwd=4fb1 
提取码:4fb1 
--来自百度网盘超级会员V3的分享

        

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/324064
推荐阅读
  

闽ICP备14008679号