热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SpringBoot+Mybatis+Vue整合

创建springboot项目添加配置spring.datasource.urljdbc:mysql:demo?serverTimezoneUTC&characterEncodin

创建springboot项目


添加配置

spring.datasource.url = jdbc:mysql:///demo?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#指定映射xml文件位置
mybatis.mapper-locations=classpath:mapper/*.xml
#端口
server.port=8888

mybatis反向生成

db.sql

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`email` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`username` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`password` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,`createDate` timestamp NULL DEFAULT NULL,`address` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '王者归来', '287664409@qq.com', 'admin', '123456', '2020-09-21 00:00:00', '北京市通州区商通大道1号');
INSERT INTO `user` VALUES ('2', '王小虎', '', 'tiger', '123456', '2020-09-22 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('3', '王小虎', '', 'tiger', '123456', '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('4', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('5', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('6', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('7', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('8', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('9', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('10', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('11', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');
INSERT INTO `user` VALUES ('12', '王小虎', null, 'tiger', null, '2020-09-23 00:00:00', '上海市普陀区金沙江路 1518');

generatorConfig.xml





jdbc.properties

jdbc.driverLocation=D:\\Software\\mysql-connector-java-8.0.11.jar
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#数据库地址
jdbc.jdbcUrl=jdbc:mysql:///demo?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
#用户名
jdbc.user=root
#密码
jdbc.password=123456
#最大连接数
c3p0.maxPoolSize=30
#最小连接数
c3p0.minPoolSize=10
#关闭连接后不自动commit
c3p0.autoCommitOnClose=false
#获取连接超时时间
c3p0.checkoutTimeout=10000
#当获取连接失败重试次数
c3p0.acquireRetryAttempts=2

运行

LoginController

/*********************************************** Copyright (C) 2019 IBM All rights reserved.********** K*I*N*G ********** B*A*C*K *******/
package com.example.demo.controller;
/*** @author Moses ** @Date 2020/9/22 12:00*/import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;@CrossOrigin
@Controller
public class LoginController {@Autowiredprivate IUserService userService;@ResponseBody@PostMapping("/login")public boolean login(User user) {return userService.findUser(user) == null;}
}

UserController

/*********************************************** Copyright (C) 2019 IBM All rights reserved.********** K*I*N*G ********** B*A*C*K *******/
package com.example.demo.controller;
/*** @author Moses ** @Date 2020/9/22 12:00*/import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controller
@RequestMapping(value = "/user")
public class UserController {@Autowiredprivate IUserService userService;@ResponseBody@GetMapping("/findById/{id}")public User findById(@PathVariable(name = "id") Integer id) {return userService.findById(id);}@ResponseBody@GetMapping("/findUserList")public List findUserList() {List list = userService.findUserList();return list;}
}

IUserService

package com.example.demo.service;import com.example.demo.entity.User;import java.util.List;public interface IUserService {User findById(Integer id);List findUserList();User findUser(User user);
}

UserServiceImpl

package com.example.demo.service.impl;import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.IUserService;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import java.util.List;@Service("userService")
public class UserServiceImpl implements IUserService {@Resourceprivate UserMapper userMapper;@Overridepublic User findById(Integer id) {return userMapper.selectByPrimaryKey(id);}@Overridepublic List findUserList() {return userMapper.findUserList();}@Overridepublic User findUser(User user) {return userMapper.findUser(user);}
}

 

DemoApplication

package com.example.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}
}

 

UserMapper.xml添加


启动

localhost:8888/user/findById/1


创建vue项目


安装node


安装vue

npm install --global vue-cli

npm install -g webpack

vue init webpack vue


安装淘宝npm

npm install -g cnpm --registry=https://registry.npm.taobao.org


安装element-ui

cnpm install element-ui --save


main.js,引入element-ui依赖

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element)

安装axios

cnpm install axios --save

main.js中全局引入axios

import axios from 'axios'
Vue.prototype.$axios = axios //

配置自动格式化和代码纠正

{"editor.formatOnSave": true,"editor.codeActionsOnSave": {"source.fixAll.eslint": true},"eslint.format.enable": true,"[vue]": {"editor.defaultFormatter": "dbaeumer.vscode-eslint"}}


config跨域配置

index.js添加

proxyTable: {'/api': {target: 'http://127.0.0.1:8888',changeOrigin: true,pathRewrite: {'^/api': ''}}},

dev.env.js添加

BASE_API: '"/api/"',

Login.vue




UserIndex.vue




UserDetail.vue




router配置

index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Login from '@/view/Login'
import UserIndex from '@/view/UserIndex'
import UserDetail from '@/view/UserDetail'
Vue.use(Router)export default new Router({routes: [{path: '/',name: 'HelloWorld',component: HelloWorld},{path: '/login',name: 'Login',component: Login},{path: '/user',name: 'UserIndex',component: UserIndex},{path: '/userDetail',name: 'UserDetail',component: UserDetail}]
})

 

启动

http://localhost:8080/#/login

 

登录跳转

点击查看

 

 


推荐阅读
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • HDFS2.x新特性
    一、集群间数据拷贝scp实现两个远程主机之间的文件复制scp-rhello.txtroothadoop103:useratguiguhello.txt推pushscp-rr ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文讨论了将HashRouter改为Router后,页面全部变为空白页且没有报错的问题。作者提到了在实际部署中需要在服务端进行配置以避免刷新404的问题,并分享了route/index.js中hash模式的配置。文章还提到了在vueJs项目中遇到过类似的问题。 ... [详细]
  • 本文提供了关于数据库设计的建议和注意事项,包括字段类型选择、命名规则、日期的加入、索引的使用、主键的选择、NULL处理、网络带宽消耗的减少、事务粒度的控制等方面的建议。同时还介绍了使用Window Functions进行数据处理的方法。通过遵循这些建议,可以提高数据库的性能和可维护性。 ... [详细]
  • POCOCLibraies属于功能广泛、轻量级别的开源框架库,它拥有媲美Boost库的功能以及较小的体积广泛应用在物联网平台、工业自动化等领域。POCOCLibrai ... [详细]
  • 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之六 || API项目整体搭建 6.1 仓储模式
    代码已上传Github+Gitee,文末有地址  书接上文:前几回文章中,我们花了三天的时间简单了解了下接口文档Swagger框架,已经完全解放了我们的以前的Word说明文档,并且可以在线进行调 ... [详细]
  • centos6.8 下nginx1.10 安装 ... [详细]
  • 如何搭建服务器环境php(2023年最新解答)
    导读:本篇文章编程笔记来给大家介绍有关如何搭建服务器环境php的相关内容,希望对大家有所帮助,一起来看看吧。本文目录一览:1、怎么搭建p ... [详细]
  • tomcat的log文件夹下有以下几种日志:1、catalina.YYYY-MM-DD.logcatalina引擎输出的日志;catalina是tomc ... [详细]
  • 基于SSL的mysql服务器的主从架构实现说明:本文选用172.16.22.1作为主服务器,172.16.22.3作为从服务器从服务器的mysql软件版 ... [详细]
author-avatar
帕格迪奥
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有