From 7a4c2e15a21848cdf6f95959cd86687811d0ff88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E5=B5=A9?= <1685140047@qq.com> Date: Wed, 20 May 2026 17:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=20=E5=85=BC=E8=81=8C=E7=AE=A1=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=20Test=E6=B5=8B=E8=AF=95=E7=B1=BB=E5=92=8Cxml?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E7=BC=96=E5=86=99=20=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=88=9B=E5=BB=BA=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/ssm/entity/ParttimeJob.java | 47 ++++++ .../src/com/ssm/entity/User.java | 38 +++++ .../src/com/ssm/mapper/ParttimeJobMapper.java | 9 ++ .../src/com/ssm/mapper/UserMapper.java | 9 ++ .../src/com/ssm/test/Test.java | 64 +++++++- moonlighting-MyBatisProject/src/config.xml | 37 ++++- moonlighting-MyBatisProject/src/database.sql | 138 ++++++++++++++++++ 7 files changed, 333 insertions(+), 9 deletions(-) create mode 100644 moonlighting-MyBatisProject/src/com/ssm/entity/ParttimeJob.java create mode 100644 moonlighting-MyBatisProject/src/com/ssm/entity/User.java create mode 100644 moonlighting-MyBatisProject/src/com/ssm/mapper/ParttimeJobMapper.java create mode 100644 moonlighting-MyBatisProject/src/com/ssm/mapper/UserMapper.java create mode 100644 moonlighting-MyBatisProject/src/database.sql diff --git a/moonlighting-MyBatisProject/src/com/ssm/entity/ParttimeJob.java b/moonlighting-MyBatisProject/src/com/ssm/entity/ParttimeJob.java new file mode 100644 index 0000000..e59fb75 --- /dev/null +++ b/moonlighting-MyBatisProject/src/com/ssm/entity/ParttimeJob.java @@ -0,0 +1,47 @@ +package com.ssm.entity; +import java.math.BigDecimal; +import java.util.Date; + +public class ParttimeJob { + private Integer jobId; + private Integer userId; + private String jobTitle; + private String jobContent; + private BigDecimal salary; + private String address; + private String status; + private Date createTime; + + public ParttimeJob() {} + + public Integer getJobId() { return jobId; } + public void setJobId(Integer jobId) { this.jobId = jobId; } + public Integer getUserId() { return userId; } + public void setUserId(Integer userId) { this.userId = userId; } + public String getJobTitle() { return jobTitle; } + public void setJobTitle(String jobTitle) { this.jobTitle = jobTitle; } + public String getJobContent() { return jobContent; } + public void setJobContent(String jobContent) { this.jobContent = jobContent; } + public BigDecimal getSalary() { return salary; } + public void setSalary(BigDecimal salary) { this.salary = salary; } + public String getAddress() { return address; } + public void setAddress(String address) { this.address = address; } + public String getStatus() { return status; } + public void setStatus(String status) { this.status = status; } + public Date getCreateTime() { return createTime; } + public void setCreateTime(Date createTime) { this.createTime = createTime; } + + @Override + public String toString() { + return "ParttimeJob{" + + "jobId=" + jobId + + ", userId=" + userId + + ", jobTitle='" + jobTitle + '\'' + + ", jobContent='" + jobContent + '\'' + + ", salary=" + salary + + ", address='" + address + '\'' + + ", status='" + status + '\'' + + ", createTime=" + createTime + + '}'; + } +} \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/com/ssm/entity/User.java b/moonlighting-MyBatisProject/src/com/ssm/entity/User.java new file mode 100644 index 0000000..de20af9 --- /dev/null +++ b/moonlighting-MyBatisProject/src/com/ssm/entity/User.java @@ -0,0 +1,38 @@ +package com.ssm.entity; +import java.util.Date; + +public class User { + private Integer userId; + private String username; + private String password; + private String phone; + private String role; + private Date createTime; + + public User() {} + + public Integer getUserId() { return userId; } + public void setUserId(Integer userId) { this.userId = userId; } + public String getUsername() { return username; } + public void setUsername(String username) { this.username = username; } + public String getPassword() { return password; } + public void setPassword(String password) { this.password = password; } + public String getPhone() { return phone; } + public void setPhone(String phone) { this.phone = phone; } + public String getRole() { return role; } + public void setRole(String role) { this.role = role; } + public Date getCreateTime() { return createTime; } + public void setCreateTime(Date createTime) { this.createTime = createTime; } + + @Override + public String toString() { + return "User{" + + "userId=" + userId + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + ", phone='" + phone + '\'' + + ", role='" + role + '\'' + + ", createTime=" + createTime + + '}'; + } +} \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/com/ssm/mapper/ParttimeJobMapper.java b/moonlighting-MyBatisProject/src/com/ssm/mapper/ParttimeJobMapper.java new file mode 100644 index 0000000..527ff2b --- /dev/null +++ b/moonlighting-MyBatisProject/src/com/ssm/mapper/ParttimeJobMapper.java @@ -0,0 +1,9 @@ +package com.ssm.mapper; +import com.ssm.entity.ParttimeJob; +import org.apache.ibatis.annotations.Select; +import java.util.List; + +public interface ParttimeJobMapper { + @Select("SELECT * FROM parttime_job") + List selectAllJobs(); +} \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/com/ssm/mapper/UserMapper.java b/moonlighting-MyBatisProject/src/com/ssm/mapper/UserMapper.java new file mode 100644 index 0000000..7286e44 --- /dev/null +++ b/moonlighting-MyBatisProject/src/com/ssm/mapper/UserMapper.java @@ -0,0 +1,9 @@ +package com.ssm.mapper; +import com.ssm.entity.User; +import org.apache.ibatis.annotations.Select; +import java.util.List; + +public interface UserMapper { + @Select("SELECT * FROM `user`") + List selectAllUsers(); +} \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/com/ssm/test/Test.java b/moonlighting-MyBatisProject/src/com/ssm/test/Test.java index a55954e..187a2aa 100644 --- a/moonlighting-MyBatisProject/src/com/ssm/test/Test.java +++ b/moonlighting-MyBatisProject/src/com/ssm/test/Test.java @@ -1,12 +1,68 @@ package com.ssm.test; -import java.io.IOException; + +import com.ssm.entity.*; +import com.ssm.mapper.*; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import java.io.InputStream; +import java.util.List; public class Test { + public static void main(String[] args) throws Exception { + // 1. 加载配置文件 + InputStream is = Resources.getResourceAsStream("config.xml"); + SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is); + SqlSession session = factory.openSession(); + + // 2. 获取Mapper对象 + UserMapper userMapper = session.getMapper(UserMapper.class); + ParttimeJobMapper jobMapper = session.getMapper(ParttimeJobMapper.class); + PostMapper postMapper = session.getMapper(PostMapper.class); + AdvertisementMapper adMapper = session.getMapper(AdvertisementMapper.class); + NoticeMapper noticeMapper = session.getMapper(NoticeMapper.class); + CarouselMapper carouselMapper = session.getMapper(CarouselMapper.class); + + // 3. 测试查询所有数据 + System.out.println("===== 用户管理模块 ====="); + List users = userMapper.selectAllUsers(); + for (User user : users) { + System.out.println(user); + } + + System.out.println("\n===== 兼职管理模块 ====="); + List jobs = jobMapper.selectAllJobs(); + for (ParttimeJob job : jobs) { + System.out.println(job); + } - public static void main(String[] args) throws IOException { + System.out.println("\n===== 帖子管理模块 ====="); + List posts = postMapper.selectAllPosts(); + for (Post post : posts) { + System.out.println(post); + } - } -} + System.out.println("\n===== 广告管理模块 ====="); + List ads = adMapper.selectAllAds(); + for (Advertisement ad : ads) { + System.out.println(ad); + } + System.out.println("\n===== 公告管理模块 ====="); + List notices = noticeMapper.selectAllNotices(); + for (Notice notice : notices) { + System.out.println(notice); + } + System.out.println("\n===== 轮播列表模块 ====="); + List carousels = carouselMapper.selectAllCarousels(); + for (Carousel carousel : carousels) { + System.out.println(carousel); + } + // 4. 关闭资源 + session.close(); + is.close(); + } +} \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/config.xml b/moonlighting-MyBatisProject/src/config.xml index 3b5222d..24d962a 100644 --- a/moonlighting-MyBatisProject/src/config.xml +++ b/moonlighting-MyBatisProject/src/config.xml @@ -1,8 +1,35 @@ - + - - + PUBLIC "-//mybatis.org//DTD Config 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-config.dtd"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/moonlighting-MyBatisProject/src/database.sql b/moonlighting-MyBatisProject/src/database.sql new file mode 100644 index 0000000..8cf0dea --- /dev/null +++ b/moonlighting-MyBatisProject/src/database.sql @@ -0,0 +1,138 @@ +-- 按题目要求:库名 ssm_工程名,你的工程是 moonlight-MyBatisProject → 库名 ssm_moonlighting +CREATE DATABASE IF NOT EXISTS ssm_moonlighting CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; +USE ssm_moonlighting; + +-- 1. 用户表(表名=实体类名小写,字段下划线命名) +CREATE TABLE `user` ( +`user_id` INT PRIMARY KEY AUTO_INCREMENT, +`username` VARCHAR(50) NOT NULL UNIQUE, +`password` VARCHAR(100) NOT NULL, +`phone` VARCHAR(11), +`role` VARCHAR(20) DEFAULT 'student', +`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `user` (username, password, phone, role) VALUES +('zhangsan', '123456', '13800138001', 'student'), +('lisi', '123456', '13800138002', 'student'), +('wangwu', '123456', '13800138003', 'student'), +('zhaoliu', '123456', '13800138004', 'student'), +('sunqi', '123456', '13800138005', 'student'), +('zhouba', '123456', '13800138006', 'student'), +('admin1', 'admin123', '13800138007', 'admin'), +('admin2', 'admin123', '13800138008', 'admin'), +('chenjiu', '123456', '13800138009', 'student'), +('wushi', '123456', '13800138010', 'student'); + +-- 2. 兼职表(表名=实体类名小写,外键 user_id 类型与 user.user_id 一致) +CREATE TABLE `parttime_job` ( +`job_id` INT PRIMARY KEY AUTO_INCREMENT, +`user_id` INT NOT NULL, +`job_title` VARCHAR(100) NOT NULL, +`job_content` TEXT, +`salary` DECIMAL(10,2), +`address` VARCHAR(200), +`status` VARCHAR(20) DEFAULT 'recruiting', +`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP, +FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `parttime_job` (user_id, job_title, job_content, salary, address, status) VALUES +(1, '校园发传单', '周末食堂门口发传单,一天80', 80.00, '学校食堂门口', 'recruiting'), +(1, '奶茶店兼职', '每天下午4-8点,15元/小时', 15.00, '学校西门奶茶店', 'recruiting'), +(2, '家教兼职', '辅导初中数学,每小时50', 50.00, '学生家中', 'recruiting'), +(3, '快递分拣', '菜鸟驿站分拣快递,按件计费', 0.80, '学校菜鸟驿站', 'recruiting'), +(4, '活动礼仪', '校庆活动礼仪,一天200', 200.00, '学校礼堂', 'recruiting'), +(5, '线上客服', '在线客服,晚班19-23点', 12.00, '线上', 'recruiting'), +(6, '校园代理', '考研机构校园代理,提成制', 0.00, '学校内', 'recruiting'), +(7, '食堂帮工', '午餐时段帮工,15元/小时', 15.00, '学校一食堂', 'recruiting'), +(8, '摄影助理', '校园活动摄影助理,一天120', 120.00, '学校操场', 'recruiting'), +(9, '文案编辑', '公众号推文编辑,一篇50', 50.00, '线上', 'recruiting'); + +-- 3. 帖子表(表名=实体类名小写,外键 user_id 类型与 user.user_id 一致) +CREATE TABLE `post` ( +`post_id` INT PRIMARY KEY AUTO_INCREMENT, +`user_id` INT NOT NULL, +`post_title` VARCHAR(100) NOT NULL, +`post_content` TEXT, +`view_count` INT DEFAULT 0, +`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP, +FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `post` (user_id, post_title, post_content, view_count) VALUES +(1, '周末兼职避雷', '分享几个不靠谱的兼职平台,大家别踩坑', 120), +(2, '家教经验分享', '做家教半年的心得,给学弟学妹们', 89), +(3, '快递兼职体验', '菜鸟驿站兼职一天,累但能学到东西', 76), +(4, '礼仪兼职要求', '想做礼仪的同学看过来,这些要求要知道', 150), +(5, '线上客服靠谱吗', '我做了一个月线上客服,真实感受', 95), +(6, '代理兼职怎么选', '校园代理的坑,教你怎么避坑', 110), +(7, '食堂兼职优缺点', '食堂兼职的好处和坏处,给大家参考', 68), (8, '摄影兼职入门', '零基础做摄影助理,这些基础要会', 130), +(9, '文案兼职接单', '学生党怎么接文案单,平台推荐', 105), +(10, '兼职防骗指南', '大学生兼职常见骗局,一定要看', 200); + +-- 4. 广告表(表名=实体类名小写) +CREATE TABLE `advertisement` ( +`ad_id` INT PRIMARY KEY AUTO_INCREMENT, +`ad_title` VARCHAR(100) NOT NULL, +`ad_url` VARCHAR(200), +`ad_img` VARCHAR(200), +`status` VARCHAR(20) DEFAULT 'active', +`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `advertisement` (ad_title, ad_url, ad_img, status) VALUES +('校园奶茶店优惠', 'https://xxx.com/tea', 'tea.jpg', 'active'), +('考研辅导班', 'https://xxx.com/ky', 'ky.jpg', 'active'), +('四六级资料', 'https://xxx.com/cet', 'cet.jpg', 'active'), +('兼职平台推广', 'https://xxx.com/job', 'job.jpg', 'active'), +('健身月卡优惠', 'https://xxx.com/fit', 'fit.jpg', 'active'), +('驾校报名优惠', 'https://xxx.com/driver', 'driver.jpg', 'active'), +('文具店开学季', 'https://xxx.com/stationery', 'stationery.jpg', 'active'), +('手机维修服务', 'https://xxx.com/phone', 'phone.jpg', 'active'), +('校园打印优惠', 'https://xxx.com/print', 'print.jpg', 'active'), +('租房信息推广', 'https://xxx.com/rent', 'rent.jpg', 'active'); + +-- 5. 公告表(表名=实体类名小写) +CREATE TABLE `notice` ( +`notice_id` INT PRIMARY KEY AUTO_INCREMENT, +`notice_title` VARCHAR(100) NOT NULL, +`notice_content` TEXT, +`publisher` VARCHAR(50), +`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `notice` (notice_title, notice_content, publisher) VALUES +('兼职平台上线通知', '校园兼职平台正式上线,欢迎同学们使用', '管理员'), +('兼职防骗提醒', '近期出现多起兼职诈骗,请大家提高警惕', '管理员'), +('周末招聘会通知', '本周末在礼堂举办兼职招聘会,欢迎参加', '管理员'), +('平台维护通知', '平台将于周三晚上维护,届时无法访问', '管理员'), +('优秀兼职评选', '平台举办优秀兼职评选,参与有奖励', '管理员'), +('兼职信息审核规则', '兼职信息审核标准更新,请注意发布要求', '管理员'), +('用户实名认证通知', '为保障安全,平台将开启实名认证', '管理员'), +('广告位招租通知', '平台首页广告位开始招租,有意者联系', '管理员'), +('论坛发帖规范', '论坛发帖需遵守规范,禁止发布违规内容', '管理员'), +('春节兼职招募', '春节期间兼职岗位招募,待遇优厚', '管理员'); + +-- 6. 轮播表(表名=实体类名小写) +CREATE TABLE `carousel` ( +`carousel_id` INT PRIMARY KEY AUTO_INCREMENT, +`carousel_title` VARCHAR(100), +`carousel_img` VARCHAR(200) NOT NULL, +`jump_url` VARCHAR(200), +`sort` INT DEFAULT 0, +`status` VARCHAR(20) DEFAULT 'active' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO `carousel` (carousel_title, carousel_img, jump_url, sort, status) VALUES +('校园兼职平台首页', 'banner1.jpg', '/index', 1, 'active'), +('周末兼职专场', 'banner2.jpg', '/job?type=weekend', 2, 'active'), +('家教兼职专区', 'banner3.jpg', '/job?type=tutor', 3, 'active'), +('线上兼职专区', 'banner4.jpg', '/job?type=online', 4, 'active'), +('寒假兼职招募', 'banner5.jpg', '/job?type=winter', 5, 'active'), +('防骗指南专题', 'banner6.jpg', '/notice/anti-fraud', 6, 'active'), +('招聘会预告', 'banner7.jpg', '/notice/job-fair', 7, 'active'), +('广告位招租', 'banner8.jpg', '/advertise', 8, 'active'), +('用户福利活动', 'banner9.jpg', '/activity', 9, 'active'), +('平台升级通知', 'banner10.jpg', '/notice/update', 10, 'active'); +