user表
/*
Navicat MySQL Data Transfer
Source Server : 何城东
Source Server Version : 50624
Source Host : localhost:3306
Source Database : user
Target Server Type : MYSQL
Target Server Version : 50624
File Encoding : 65001
Date: 2019-08-30 12:48:21
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`pass` varchar(255) DEFAULT NULL,
`sexid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', '何城东', '521', '1');
INSERT INTO `user` VALUES ('2', '李冠频', '123', '1');
INSERT INTO `user` VALUES ('3', '李明杨', '456', '1');
INSERT INTO `user` VALUES ('4', '贺小田 ', '789 ', '1');
INSERT INTO `user` VALUES ('5', '彭婕', '111', '0');
INSERT INTO `user` VALUES ('6', '刘艳玲', '121', '0');
INSERT INTO `user` VALUES ('7', '胡雪宁', '122', '0');
INSERT INTO `user` VALUES ('8', '简学云', '445', '1');
INSERT INTO `user` VALUES ('9', '郭圆', '777', '0');
INSERT INTO `user` VALUES ('10', '隆琴', '999', '0');
INSERT INTO `user` VALUES ('11', '公子', '269', '0');
usersex表
/*
Navicat MySQL Data Transfer
Source Server : 何城东
Source Server Version : 50624
Source Host : localhost:3306
Source Database : user
Target Server Type : MYSQL
Target Server Version : 50624
File Encoding : 65001
Date: 2019-08-30 12:48:34
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for usersex
-- ----------------------------
DROP TABLE IF EXISTS `usersex`;
CREATE TABLE `usersex` (
`sexid` int(11) NOT NULL,
`sex` varchar(255) NOT NULL,
PRIMARY KEY (`sexid`,`sex`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of usersex
-- ----------------------------
INSERT INTO `usersex` VALUES ('0', '女');
INSERT INTO `usersex` VALUES ('1', '男');
接下来把原有的application.protest删了,新建application.yml,并在里面放入如图
server:
port: 8080
spring:
mvc:
view:
suffix: .jsp
prefix: /WEB-INF/jsp/
datasource:
name: test
url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf8
username: root
password: 521
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.example.springbootmybatisjsp.entity
4.0.0
com.dalaoyang
springboot_jsp
0.0.1-SNAPSHOT
war
springboot_jsp
springboot_jsp
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-devtools
runtime
org.springframework.boot
spring-boot-starter-test
test
org.webjars
jquery
3.3.1
org.webjars
bootstrap
4.0.0
mysql
mysql-connector-java
5.1.6
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.5
com.github.pagehelper
pagehelper
5.1.2
org.apache.tomcat.embed
tomcat-embed-jasper
provided
javax.servlet
jstl
org.springframework.boot
spring-boot-maven-plugin
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.1
${basedir}/src/main/resources/generator/generatorConfig.xml
true
true
我这里是两表联查
user
package com.example.springbootmybatisjsp.entity;
public class user {
public int id;
public String name;
public String pass;
public int sexid;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public int getSexid() {
return sexid;
}
public void setSexid(int sexid) {
this.sexid = sexid;
}
private usersex userid;
public usersex getUserid() {
return userid;
}
public void setUserid(usersex userid) {
this.userid = userid;
}
@Override
public String toString() {
return "user{" +
"id=" + id +
", name='" + name + '\'' +
", pass='" + pass + '\'' +
", sexid=" + sexid +
", userid=" + userid +
'}';
}
}
usersex
package com.example.springbootmybatisjsp.entity;
import java.util.List;
public class usersex {
public int getSexid() {
return sexid;
}
public void setSexid(int sexid) {
this.sexid = sexid;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public List getUser() {
return user;
}
public void setUser(List user) {
this.user = user;
}
public int sexid;
public String sex;
public List user;
}
userMapper
package com.example.springbootmybatisjsp.mapper;
import com.example.springbootmybatisjsp.entity.user;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface userMapper {
Listgetall();
}
userMapper.xml
usercontroller
package com.example.springbootmybatisjsp.controller;
import com.example.springbootmybatisjsp.entity.user;
import com.example.springbootmybatisjsp.mapper.userMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class usercontroller {
//从容器中获取
@Autowired
private userMapper userMapper;
@RequestMapping("/success")
public PageInfo success(@RequestParam(value = "page" ,defaultValue = "1") int page, ModelMap mod){
PageHelper.startPage(page, 5);
List userList= userMapper.getall();
PageInfo pages = new PageInfo(userList,5);
mod.addAttribute("PageInfo",pages);
return pages;
}
}
success.jsp
<%--
Created by IntelliJ IDEA.
User: 何城东
Date: 2019/8/29
Time: 20:57
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Title
用户列表
编号
用户名
密码
性别
删除
修改
${c.id}
${c.name}
${c.pass}
${c.userid.sex}
当前第${PageInfo.pageNum}页,总共${PageInfo.pages}页,总共${PageInfo.total}条记录