链接:https://pan.baidu.com/s/1jSU_6U36oavwhXPWQArPTA
提取码:rapz
/*
SQLyog Ultimate v12.5.0 (64 bit)
MySQL - 5.5.59 : Database - tb_user
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`tb_user` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `tb_user`;
/*Table structure for table `tb_user` */
DROP TABLE IF EXISTS `tb_user`;
CREATE TABLE `tb_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(50) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`sex` int(11) DEFAULT NULL,
`birthday` date DEFAULT NULL,
`created` date DEFAULT NULL,
`updated` date DEFAULT NULL,
`note` varchar(50) DEFAULT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;
/*Data for the table `tb_user` */
insert into `tb_user`(`id`,`username`,`password`,`name`,`age`,`sex`,`birthday`,`created`,`updated`,`note`) values
(13,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(16,'zhangsan12345',NULL,'zhang',234,NULL,NULL,NULL,NULL,NULL),
(17,'Java2',NULL,'java2',23,NULL,NULL,NULL,NULL,NULL);
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
package com.czxy.controller;
import com.czxy.pojo.PageResult;
import com.czxy.pojo.User;
import com.czxy.pojo.UserVo;
import com.czxy.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@RequestMapping("/index")
public String html() {
return "/index";
}
/**
* 查询所有
*
* @return
*/
@RequestMapping("/findAll")
@ResponseBody
public PageResult queryUserByPage(UserVo userVo) {
PageInfo pageInfo = userService.findAll(userVo.getPage(), userVo.getRow());
return new PageResult(pageInfo.getTotal(), pageInfo.getList());
}
/**
* 通过id查询
*
* @param id
* @return
*/
@RequestMapping("/findById")
@ResponseBody
public User findById(Integer id) {
return userService.findById(id);
}
/**
* 删除
*
* @param id
*/
@RequestMapping("/deleteById")
@ResponseBody
public void delete(Integer id) {
userService.delete(id);
}
/**
* 编辑
*
* @param id
*/
@RequestMapping("/editById")
@ResponseBody
public void edit(Integer id) {
userService.edit(id);
}
/**
* 添加
*/
@RequestMapping("/insert")
@ResponseBody
public String insert(User user) {
userService.insert(user);
return "添加成功";
}
}
package com.czxy.dao;
import com.czxy.pojo.User;
import tk.mybatis.mapper.common.Mapper;
@org.apache.ibatis.annotations.Mapper
public interface UserMapper extends Mapper<User> {
}
package com.czxy.service;
import com.czxy.dao.UserMapper;
import com.czxy.pojo.PageResult;
import com.czxy.pojo.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class UserService {
@Resource
private UserMapper userMapper;
public PageInfo<User> findAll(Integer pageMum, Integer pageSize) {
PageHelper.startPage(pageMum, pageSize);
List<User> list = userMapper.selectAll();
return new PageInfo<>(list);
}
public User findById(Integer id) {
return userMapper.selectByPrimaryKey(id);
}
public void delete(Integer id) {
userMapper.deleteByPrimaryKey(id);
}
public void edit(Integer id) {
User user = userMapper.selectByPrimaryKey(id);
userMapper.updateByPrimaryKey(user);
}
public void insert(User user) {
userMapper.insert(user);
}
}
’
# 映射端口
server.port=80
# 连接四大金刚 等号前面是key,是固定写法,等号后面是根据自己的数据库来定义
spring.datasource.url=jdbc:mysql://localhost:3306/tb_user
spring.datasource.username=root
spring.datasource.password=
# 可省略,SpringBoot自动推断 驱动
spring.datasource.driverClassName=com.mysql.jdbc.Driver
# druid连接池
#初始化连接数
spring.datasource.druid.initial-size=1
#最小空闲连接
spring.datasource.druid.min-idle=1
#最大活动连接
spring.datasource.druid.max-active=20
#获取连接时测试是否可用
spring.datasource.druid.test-on-borrow=true
#监控页面启动
spring.datasource.druid.stat-view-servlet.allow=true
#MVC
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html
spring.resources.static-locations=classpath:templates,classpath:static
# 是否开启模板缓存,默认true
spring.thymeleaf.cache=false
# 指定模板的模式,具体查看StandardTemplateModeHandlers,默认为: HTML5
spring.thymeleaf.mode=HTML5