day10
commit
635d216323
|
@ -0,0 +1,33 @@
|
||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
|
@ -0,0 +1,139 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.bwie</groupId>
|
||||||
|
<artifactId>Zg6-day10</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>Zg6-day10</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>2.3.12.RELEASE</spring-boot.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!--mybatis plus依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus</artifactId>
|
||||||
|
<version>3.5.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 添加servlet依赖模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- 添加jstl标签库依赖模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>jstl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--添加tomcat依赖模块.-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- sqring框架依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.1.4</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 热部署依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mysql数据库依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.32</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- lombok小辣椒依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<!-- 测试类依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.4.14</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.bwie.Zg6Day10Application</mainClass>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>repackage</id>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Navicat Premium Data Transfer
|
||||||
|
|
||||||
|
Source Server : zhangteng
|
||||||
|
Source Server Type : MySQL
|
||||||
|
Source Server Version : 80038
|
||||||
|
Source Host : localhost:3306
|
||||||
|
Source Schema : zg6_day10
|
||||||
|
|
||||||
|
Target Server Type : MySQL
|
||||||
|
Target Server Version : 80038
|
||||||
|
File Encoding : 65001
|
||||||
|
|
||||||
|
Date: 29/07/2024 09:04:03
|
||||||
|
*/
|
||||||
|
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for user
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `user`;
|
||||||
|
CREATE TABLE `user` (
|
||||||
|
`uid` int NOT NULL AUTO_INCREMENT,
|
||||||
|
`user_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
||||||
|
`pwd` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
||||||
|
`sex` int NULL DEFAULT NULL,
|
||||||
|
`birthday` date NULL DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`uid`) USING BTREE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Records of user
|
||||||
|
-- ----------------------------
|
||||||
|
INSERT INTO `user` VALUES (1, 'Tang Xiaoming', 'HD7h11e1EE', 28, '2024-01-26');
|
||||||
|
INSERT INTO `user` VALUES (2, 'Ma Anqi', 'CijZwta359', 36, '2022-11-11');
|
||||||
|
INSERT INTO `user` VALUES (3, 'Feng Lu', '3klALW7ruc', 15, '2005-12-25');
|
||||||
|
INSERT INTO `user` VALUES (4, 'Chan Ka Keung', '18s4irlHHY', 19, '2014-03-12');
|
||||||
|
INSERT INTO `user` VALUES (5, 'Lau Kar Yan', 'sjTKp1GYO7', 20, '2001-05-08');
|
||||||
|
INSERT INTO `user` VALUES (6, 'Edward Ford', 'WsLjB2WtXl', 22, '2000-12-25');
|
||||||
|
INSERT INTO `user` VALUES (7, 'Su Rui', '1H5IWcwCpw', 24, '2014-01-15');
|
||||||
|
INSERT INTO `user` VALUES (8, 'Mao Xiaoming', 'xvxlqgRaRa', 17, '2013-06-15');
|
||||||
|
INSERT INTO `user` VALUES (9, 'Wu Wai Man', 'anieWa6ucy', 18, '2011-02-09');
|
||||||
|
INSERT INTO `user` VALUES (10, 'Jack Crawford', 'ah01L6yUah', 19, '2005-09-22');
|
||||||
|
INSERT INTO `user` VALUES (11, 'Li Zitao', '5XltQshPpH', 22, '2006-08-05');
|
||||||
|
INSERT INTO `user` VALUES (12, 'Vincent Hall', 'QqzPbIggo1', 30, '2020-12-28');
|
||||||
|
INSERT INTO `user` VALUES (13, 'Cheng Yunxi', 'bNlbBkAkOx', 34, '2020-10-08');
|
||||||
|
INSERT INTO `user` VALUES (14, 'Wong Chung Yin', '8kElRuaVDS', 32, '2017-11-18');
|
||||||
|
INSERT INTO `user` VALUES (15, 'Jiang Lu', 'FXvsbHi3At', 36, '2024-01-23');
|
||||||
|
INSERT INTO `user` VALUES (16, 'Kato Daichi', 'bAFncjRTtd', 26, '2001-10-01');
|
||||||
|
INSERT INTO `user` VALUES (17, 'Janice Hayes', 'TGbLq60ztW', 29, '2018-07-09');
|
||||||
|
INSERT INTO `user` VALUES (18, 'Zeng Lu', 'ZI159BEJel', 21, '2008-08-11');
|
||||||
|
INSERT INTO `user` VALUES (19, 'Nishimura Mitsuki', '8kgwfxeiau', 23, '2019-10-31');
|
||||||
|
INSERT INTO `user` VALUES (20, 'Zeng Anqi', 'sGpPro6mvx', 24, '2018-06-10');
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.bwie;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.bwie.mapper")
|
||||||
|
public class Zg6Day10Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Zg6Day10Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.bwie.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.bwie.pojo.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.bwie.mapper
|
||||||
|
* @Project:Zg6-day10
|
||||||
|
* @name:UserMapper
|
||||||
|
* @Date:2024/7/29 8:46
|
||||||
|
*/
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.bwie.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.bwie.pojo
|
||||||
|
* @Project:Zg6-day10
|
||||||
|
* @name:User
|
||||||
|
* @Date:2024/7/29 8:45
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private Integer uid;
|
||||||
|
private String userName;
|
||||||
|
private String pwd;
|
||||||
|
private Integer sex;
|
||||||
|
private Date birthday;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
# 应用服务 WEB 访问端口号
|
||||||
|
server.port=8080
|
||||||
|
|
||||||
|
# 日志输出
|
||||||
|
logging.level.com.bawei=debug
|
||||||
|
# 数据库驱动:
|
||||||
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
|
# 数据源名称
|
||||||
|
#spring.datasource.name=defaultDataSource
|
||||||
|
# 数据库连接地址
|
||||||
|
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/zg6_day10?characterEncoding=utf-8&useUnicode=true
|
||||||
|
# 数据库用户名&密码:
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=root
|
||||||
|
# 视图解析器
|
||||||
|
spring.mvc.view.prefix=/WEB-INF/view/
|
||||||
|
spring.mvc.view.suffix=.jsp
|
||||||
|
|
||||||
|
# mybatis下划线转小驼峰
|
||||||
|
mybatis.configuration.map-underscore-to-camel-case=true
|
||||||
|
|
||||||
|
|
||||||
|
# pageHelper插件
|
||||||
|
# 分页合理化
|
||||||
|
pagehelper.reasonable=true
|
||||||
|
# 分页自动转换方言。。。不同的数据库 分页的语句是不同的 mysql--limit oracle--rownum
|
||||||
|
pagehelper.auto-dialect=true
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bwie.mapper.UserMapper">
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.bwie;
|
||||||
|
|
||||||
|
import com.bwie.mapper.UserMapper;
|
||||||
|
import com.bwie.pojo.User;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class Zg6Day10ApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能查询所有学生
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void selectAll() {
|
||||||
|
List<User> users = userMapper.selectList(null);
|
||||||
|
users.forEach(user -> {
|
||||||
|
System.out.println(user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能:根据id删除学生
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void deleteStu(){
|
||||||
|
int i = userMapper.deleteById(3);
|
||||||
|
if (i>0){
|
||||||
|
System.out.println("删除成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 功能:列表查询年龄降序排序
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void selectByAge(){
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put("19",19);
|
||||||
|
List<User> users = userMapper.selectByMap(map);
|
||||||
|
users.forEach(user -> {
|
||||||
|
System.out.println(user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue