完成用户管理 兼职管理模块 Test测试类和xml文件的编写 以及创建数据库连接数据库

main
韩嵩 2 weeks ago
parent e478812dd2
commit 7a4c2e15a2

@ -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 +
'}';
}
}

@ -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 +
'}';
}
}

@ -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<ParttimeJob> selectAllJobs();
}

@ -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<User> selectAllUsers();
}

@ -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<User> users = userMapper.selectAllUsers();
for (User user : users) {
System.out.println(user);
}
System.out.println("\n===== 兼职管理模块 =====");
List<ParttimeJob> jobs = jobMapper.selectAllJobs();
for (ParttimeJob job : jobs) {
System.out.println(job);
}
public static void main(String[] args) throws IOException {
System.out.println("\n===== 帖子管理模块 =====");
List<Post> posts = postMapper.selectAllPosts();
for (Post post : posts) {
System.out.println(post);
}
}
}
System.out.println("\n===== 广告管理模块 =====");
List<Advertisement> ads = adMapper.selectAllAds();
for (Advertisement ad : ads) {
System.out.println(ad);
}
System.out.println("\n===== 公告管理模块 =====");
List<Notice> notices = noticeMapper.selectAllNotices();
for (Notice notice : notices) {
System.out.println(notice);
}
System.out.println("\n===== 轮播列表模块 =====");
List<Carousel> carousels = carouselMapper.selectAllCarousels();
for (Carousel carousel : carousels) {
System.out.println(carousel);
}
// 4. 关闭资源
session.close();
is.close();
}
}

@ -1,8 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- mybatis全局配置文件 -->
<configuration>
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 开启下划线转驼峰,解决数据库字段与实体类属性映射问题 -->
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<!-- 实体类别名 -->
<typeAliases>
<package name="com.ssm.entity"/>
</typeAliases>
<!-- 数据库环境配置 -->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ssm_moonlighting?useSSL=false&amp;serverTimezone=UTC&amp;characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value="125116"/>
</dataSource>
</environment>
</environments>
<!-- 注册Mapper接口 -->
<mappers>
<package name="com.ssm.mapper"/>
</mappers>
</configuration>

@ -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');
Loading…
Cancel
Save