Java后端开发工程师简历加分项:公众号个人简历搭建
Posted 被雨遗忘的夏天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java后端开发工程师简历加分项:公众号个人简历搭建相关的知识,希望对你有一定的参考价值。
概述:
五一小长假,找个小项目复习复习JavaWeb、JavaEE基础。
项目很简单,就是实现数据库的增删改查,分为五大模块,分别是
基本信息模块(User)
教育经历模块(Edu)
工作经历模块(Work)
技能模块(Skill)
特长模块(Specialty)
五个模块的基本原理一样,所以我主要围绕基本信息模块(User)讲解。
也可以往下翻,先看看项目效果图哟!
GitHub地址,欢迎fork&start!!
一、 项目结构
二、 操作流程
三、 数据库设计-基础信息表(user)
* id
* 姓名 name
* 年龄 age
* 地区 city
* 现住址 address
* 邮箱 email
* 电话 phone
* 微信 weixin
* qq qq
* 微博地址 Weibo
* 个人简介 info
```sql
CREATE TABLE `user` (
`id` bigint(20) NOT NULL COMMENT '用户唯一标示,用于关联教育经历、工作经历、特长以及技能列表',
`name` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '姓名',
`age` int(8) NULL COMMENT '年龄',
`city` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '地区城市',
`address` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '详细地址',
`email` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '邮箱地址',
`phone` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '电话或手机号码',
`weixin` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '微信号码',
`qq` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'qq号码',
`weibo` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '微博地址',
`description` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '个人简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
COMMENT='用户基础信息表,包含了用户的基本信息'
ROW_FORMAT=DYNAMIC
AVG_ROW_LENGTH=0;
```
四、 接口文档
1、 请求URL
http://域名/v1/user/insert
2、 请求方式
post
3、 参数类型:param
4、返回示例
{
status:0,// 状态码,0表示正常,-1表示错误
msg:"用户新增成功",// 返回的消息
data:1// 本次新增的用户的编号,用于新增其他信息的userid参数
}
五、 项目效果图
1、 填写信息(有五个表,现在展示基本信息表)
2、 填写完表格生成个人专属简历地址(到时绑定公众号,关注即可观看个人简历)
3、 简历效果图
PS:额,,服务器备案还在进行中,所以现在只能在本地部署,
部署的前提准备是公众号+域名+云服务器+备案。
(云服务器需要三个月以上才可以备案哟!)
别急!!!等我备案通过了,再更新部署云端服务器以及公众号的内容!!!!!
六、 基本信息模块核心代码
1、 controller
package com.lsy.controller;
import com.lsy.bean.Result;
import com.lsy.bean.User;
import com.lsy.service.DBService;
import com.lsy.util.DBUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author lsy
* @description: 控制器
* @date: 2021/5/3 23:27
* @param: null
* @return:
* @version 1.0
*/
@WebServlet("/v1/user/insert")
public class UserInsertServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 1. 接收前端发送的数据
String ageText = request.getParameter("age");
int age = Integer.parseInt(ageText);
String name = request.getParameter("name");
String city = request.getParameter("city");
String address = request.getParameter("address");
String email = request.getParameter("email");
String phone = request.getParameter("phone");
String weixin = request.getParameter("weixin");
String qq = request.getParameter("qq");
String weibo = request.getParameter("weibo");
String sex = request.getParameter("sex");
String description = request.getParameter("description");
// 2. 通过前端发送的数据,组装为user
User user = new User(name, age, city, address, email, phone, weixin, qq, weibo, sex, description);
// 3. 操作Service,完成用户信息的存储
int userId = DBService.inserUser(user);
// 4. 将存储的结果,组装成为JSON格式数据
Result result = null;
if (userId == -1) {
result = new Result(-1, "新增用户失败");
} else {
result = new Result(1, "新增用户成功");
}
String json = result.toJSON();
// 5. 将JSON数据返回给前端
response.getWriter().append(json);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
2、 bean
package com.lsy.bean;
import java.util.Objects;
/**
* @ClassName User
* @Description 用户bean,打包数据
* @date 2021/5/1 10:18
* @Version 1.0
*/
public class User {
// 用户Id
private int id;
// 用户名称
private String name;
// 用户年龄
private int age;
// 用户城市
private String city;
// 用户地址
private String address;
// 用户邮箱
private String email;
// 用户电话
private String phone;
// 用户微信
private String weixin;
// 用户qq
private String qq;
// 用户微博
private String weibo;
// 用户性别
private String sex;
// 个人介绍
private String description;
// 全参构造方法
public User(int id, String name, int age, String city, String address, String email, String phone, String weixin, String qq, String weibo, String sex, String description) {
this.id = id;
this.name = name;
this.age = age;
this.city = city;
this.address = address;
this.email = email;
this.phone = phone;
this.weixin = weixin;
this.qq = qq;
this.weibo = weibo;
this.sex = sex;
this.description = description;
}
// 无参构造方法
public User() {
}
// 前端传来的参数,无ID
public User(String name, int age, String city, String address, String email, String phone, String weixin, String qq, String weibo, String sex, String description) {
this.name = name;
this.age = age;
this.city = city;
this.address = address;
this.email = email;
this.phone = phone;
this.weixin = weixin;
this.qq = qq;
this.weibo = weibo;
this.sex = sex;
this.description = description;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\\'' +
", age=" + age +
", city='" + city + '\\'' +
", address='" + address + '\\'' +
", email='" + email + '\\'' +
", phone='" + phone + '\\'' +
", weixin='" + weixin + '\\'' +
", qq='" + qq + '\\'' +
", weibo='" + weibo + '\\'' +
", sex='" + sex + '\\'' +
", description='" + description + '\\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return id == user.id &&
age == user.age &&
Objects.equals(name, user.name) &&
Objects.equals(city, user.city) &&
Objects.equals(address, user.address) &&
Objects.equals(email, user.email) &&
Objects.equals(phone, user.phone) &&
Objects.equals(weixin, user.weixin) &&
Objects.equals(qq, user.qq) &&
Objects.equals(weibo, user.weibo) &&
Objects.equals(sex, user.sex) &&
Objects.equals(description, user.description);
}
@Override
public int hashCode() {
return Objects.hash(id, name, age, city, address, email, phone, weixin, qq, weibo, sex, description);
}
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getWeixin() {
return weixin;
}
public void setWeixin(String weixin) {
this.weixin = weixin;
}
public String getQq() {
return qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public String getWeibo() {
return weibo;
}
public void setWeibo(String weibo) {
this.weibo = weibo;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
package com.lsy.bean;
import com.alibaba.fastjson.JSON;
/**
* @ClassName Result
* @Description 将Java中的对象,转化为JSON格式字符串
* @date 2021/5/3 21:28
* @Param
* @return
*/
public class Result {
// 状态
private int status;
// 消息文字
private String msg;
// 数据
private Object data;
// 组装为JSON数据
public String toJSON() {
return JSON.toJSONString(this);
}
public Result() {
}
public Result(int status) {
this.status = status;
}
public Result(int status, String msg) {
this.status = status;
this.msg = msg;
}
public Result(int status, String msg, Object data) {
this.status = status;
this.msg = msg;
this.data = data;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
3、 service
package com.lsy.service;
import com.lsy.bean.User;
import com.lsy.dao.BaseDao;
import com.lsy.dao.UserDao;
/**
* @ClassName DBService
* @Description 代理dao,可以理解为菜市场和保姆的关系
* @date 2021/5/1 12:42
* @Param
* @return
*/
public class DBService {
private static BaseDao<User> userDao = new UserDao();
public static int inserUser(User user) {
return userDao.insert(user);
}
public static User findByUserId(int userId) {
return userDao.findByUserId(userId);
}
}
4、 dao
package com.lsy.dao;
/**
* @ClassName BaseDao
* @Description 用于定义数据操作对象的 存取标准
* @date 2021/5/1 10:36
* @Version 1.0
* @Param <T> 操作的数据类型:用户的基本信息、学历信息、工作经验、特长、技能列表
*/
public interface BaseDao<T> {
/**
* @author lsy
* @description: 用于规范存储
* @date: 2021/5/1 14:23
* @param: t 要存储的数据
* @return: 存储的结果,大于0表示成功
* @version 1.0
*/
int insert(T t);
/**
* @author lsy
* @description: 用于规范获取
* @date: 2021/5/1 14:24
* @param: userId 基于用户的编号,查询数据
* @return: 基于用户的编号,查询到的数据:用户基本信息、学历信息等
* @version 1.0
*/
T findByUserId(int userId);
}
package com.lsy.dao;
import com.lsy.bean.User;
import com.lsy.util.DBUtil;
import java.sql.*;
/**
* @ClassName UserDao
* @Description 数据库操作
* @date 2021/5/1 14:52
* @Param
* @return
*/
public class UserDao implements BaseDao<User> {
// 用于操作数据库存储的sql
private static final String SQL_INSERT = "insert into " +
"kkb_user(name,age,city,address,email,phone,weixin,qq,weibo,sex,description) " +
"values(?,?,?,?,?,?,?,?,?,?,?)";
// 用于操作数据库获取用户基本信息的sql
private static final String SQL_FIND_BY_USERID = "select * from kkb_user where id=?";
@Override
public int insert(User user) {
// 1. 获取数据库的连接 : conn
Connection conn = DBUtil.getConn();
// 2. 通过连接 conn 创建执行sql语句的环境: statemet, 并预编译SQL
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
// 3. 向执行环境中,填充?所表示的参数
statement.setString(1, user.getName());
statement.setInt(2, user.getAge());
statement.setString(3, user.getCity());
statement.setString(4, user.getAddress());
statement.setString(5, user.getEmail());
statement.setString(6, user.getPhone());
statement.setString(7, user.getWeixin());
statement.setString(8, user.getQq());
statement.setString(9, user.getWeibo());
statement.setString(10, user.getSex());
statement.setString(11, user.getDescription());
// 4. 执行SQL
statement.executeLargeUpdate();
// 5. 获取新增的用户的ID
result = statement.getGeneratedKeys();
if (result.next()) {
// 6. 将新增的用户的标识(id),作为此段代码的执行结果 返回
return result.getInt(1);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
// 7.把连接释放
DBUtil.close(conn,statement,result);
}
return -1;
}
@Override
public User findByUserId(int userId) {
// 1. 获取数据库的连接 : conn
Connection conn = DBUtil.getConn();
// 2. 通过连接 conn 创建执行sql语句的环境: statemet, 并预编译SQL
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(SQL_FIND_BY_USERID);
// 3. 向执行环境中,填充?所表示的参数
statement.setInt(1,userId);
// 4. 执行SQL, 并获取执行的结果集
result = statement.executeQuery();
// 5. 取出结果集中的用户的各个信息,组装成一个user
if (result.next()) {
int age = result.getInt("age");
String name = result.getString("name");
String city = result.getString("city");
String address = result.getString("address");
String email = result.getString("email");
String phone = result.getString("phone");
String weixin = result.getString("weixin");
String qq = result.getString("qq");
String weibo = result.getString("weibo");
String sex = result.getString("sex");
String description = result.getString("description");
User user = new User(userId, name, age, city, address, email, phone, weixin, qq, weibo, sex, description);
// 6. 将组装完毕的user,作为此段代码的执行结果,返回给调用者
return user;
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
// 7. 释放资源
DBUtil.close(conn,statement,result);
}
return null;
}
}
5、 util
package com.lsy.util;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
/**
* @author lsy
* @description: 数据库连接工具
* @date: 2021/5/1 14:36
* @param: null
* @return:
* @version 1.0
*/
public class DBUtil {
// 操作数据库的三要素
private static String url = "";
private static String user = "";
private static String password = "";
public DBUtil() {
}
/**
* @author lsy
* @description: 用于链接数据库,得到的结果是数据库的连接对象,连接对象具备了操作数据库的很多功能
* @date: 2021/5/1 14:39
* @param:
* @return: 连接对象
* @version 1.0
*/
public static Connection getConn() {
try {
Connection conn = DriverManager.getConnection(url, user, password);
return conn;
} catch (SQLException var1) {
var1.printStackTrace();
return null;
}
}
/**
* @author lsy
* @description: 断开数据库资源的链接,用于释放资源
* @date: 2021/5/1 14:41
* @param: conn 要释放的链接
* statement 要释放的执行环境
* resultSet 要释放的结果集
* @version 1.0
*
* 连接原则: 尽可能晚的连接数据库,尽可能早的释放资源
*/
public static void close(Connection conn, Statement statement, ResultSet resultSet) {
if (conn != null) {
try {
conn.close();
} catch (SQLException var6) {
var6.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException var5) {
var5.printStackTrace();
}
}
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException var4) {
var4.printStackTrace();
}
}
}
// 加载配置文件,获取文件中的三要素
static {
Properties ppt = new Properties();
InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("db.properties");
try {
ppt.load(is);
url = ppt.getProperty("url");
user = ppt.getProperty("user");
password = ppt.getProperty("password");
} catch (IOException var4) {
var4.printStackTrace();
}
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException var3) {
var3.printStackTrace();
}
}
}
6、filter
package com.lsy.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
/**
* @author lsy
* @description: 过滤全部
* @date: 2021/5/3 21:01
* @param: null
* @return:
* @version 1.0
*/
@WebFilter("/*")
public class CharSetFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
// 调整请求编码为UTF-8
req.setCharacterEncoding("utf-8");
// 调整响应编码为UTF-8
resp.setCharacterEncoding("utf-8");
// 放行
chain.doFilter(req, resp);
}
public void init(FilterConfig config) throws ServletException {
}
}
7、 数据库配置文件db.properties
url=jdbc:mysql://localhost:3306/homepage?serverTimezone=GMT&characterEncoding=utf-8
user=用户名
password=用户密码
以上是关于Java后端开发工程师简历加分项:公众号个人简历搭建的主要内容,如果未能解决你的问题,请参考以下文章