所需资料
功能主体说明:
- 问题编辑与删除
- 引入markdown插件
- mybatis-plus 的创建时间和修改时间自动生成
项目目录
登录后点击我的问题跳转到自己发布的问题页面
navigation.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container-fluid" th:fragment="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">码匠社区</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">码匠社区</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="搜索问题">
</div>
<button type="submit" class="btn btn-default">搜索</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li th:if="${session.user !=null}">
<a href="/publish" class="btn btn-default">发布</a>
</li>
<li class="dropdown" th:if="${session.user!=null}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">
<span th:text="${session.user.getFdName()}"></span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="/profile/question">我的问题</a></li>
<li><a href="#">退出登录</a></li>
</ul>
</li>
<li th:if="${session.user==null}"><a
th:href="@{'https://gitee.com/oauth/authorize'+'?client_id='+${client_id}+'&redirect_uri='+${redirect_uri}+'&response_type=code&state=1'}">登录</a>
</li>
</ul>
</div>
</div>
</body>
</html>
index.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>码匠问题社区</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>-->
<!--<script type="text/javascript" src="/js/jquery.js"></script>-->
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/css/community.css"/>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid" th:replace="navigation::navigation"></div>
</nav>
<div class="container-fluid main">
<div class="row">
<div class="col-md-9 col-md-12 col-sm-12 col-xs-12">
<h2><span class="glyphicon glyphicon-list"/>发现</h2>
<hr>
<div class="media" th:each="questionDTO :${questionPageList.getList()}">
<div class="media-left">
<a href="#">
<img class="img-rounded"
th:src="${questionDTO.user.getAvatarUrl()}">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">
<a th:href="@{'/question/'+${questionDTO.getId()}}" th:text="${questionDTO.getTitle()}"></a>
</h4>
<span th:text="${questionDTO.tag}"></span><br>
<span class="text-desc">
• <span th:text="${questionDTO.getUser().getFdName()}"></span>发表了文章
• <span th:text="${questionDTO.getCommentCount()}"></span> 个评论
• <span th:text="${questionDTO.getLikeCount()}"></span> 次浏览
•<span th:text="${#dates.format(questionDTO.getGmtCreate(),'yyyy-MM-dd')}"></span>发布
</span>
</div>
</div>
<nav aria-label="Page navigation">
<ul class="pagination">
<li th:if="${questionPageList.getCurrPage()!=1}">
<a th:href="@{/(current=1,size=${questionPageList.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true"><<</span><!--首页-->
</a>
</li>
<li th:if="${questionPageList.getCurrPage()!=1}">
<a th:href="@{/(current=${questionPageList.getCurrPage()-1},size=${questionPageList.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true"><</span><!--上一页-->
</a>
</li>
<li th:each="page:${questionPageList.getPageNumber()}" th:class="${questionPageList.getCurrPage()==page}?'active' : ''">
<a th:href="@{/(current=${page},size=${questionPageList.getPageSize()})}" th:text="${page}"></a>
</li>
<li th:if="${questionPageList.getCurrPage()!=questionPageList.getTotalPage()}">
<a th:href="@{/(current=${questionPageList.getCurrPage()+1},size=${questionPageList.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true">></span><!--下一页-->
</a>
</li>
<li th:if="${questionPageList.getCurrPage()!=questionPageList.getTotalPage()}">
<a th:href="@{/(current=${questionPageList.getTotalPage()},size=${questionPageList.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true">>></span><!--尾页-->
</a>
</li>
</ul>
</nav>
</div>
<div class="col-md-3 col-md-12 col-sm-12 col-xs-12">
<h3>问题发起指南</h3>
• 问题标题: 请用精简的语言描述您发布的问题,不超过25字 <br>
• 问题补充: 详细补充您的问题内容,并确保问题描述清晰直观, 并提供一些相关的资料<br>
• 选择标签: 选择一个或者多个合适的标签,用逗号隔开,每个标签不超过10个字<br>
</div>
</div>
</div>
</body>
</html>
ProfileController
package com.majiang.community.controller;
import com.majiang.community.model.User;
import com.majiang.community.service.IQuestionService;
import com.majiang.community.util.CookieUtil;
import com.majiang.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
/**
* @date 2022-04-28
*/
@Controller
public class ProfileController {
@Autowired(required = false)
private IQuestionService questionService;
@GetMapping("profile/{action}")
public String profile(@RequestParam(name="current",defaultValue = "0") int current,
@RequestParam(name="size",defaultValue = "4")int size,
@PathVariable(name = "action")String action,
HttpServletRequest request,
Model model){
User user = (User) request.getSession().getAttribute("user");
//cookie已经过期
if(user==null){
return "redirect:/";
}
//获取我的问题列表
if("question".equals(action)){
PageUtils myQuestionPage= questionService.selectMyQuestion(current,size,user);
model.addAttribute("sectionName", "问题列表");
model.addAttribute("section", "question");
model.addAttribute("myQuestionPage", myQuestionPage);
}
//获取我的回复列表
if("reply".equals(action)){
model.addAttribute("action", "回复列表");
}
return "profile";
}
}
具体实现 QuestionServiceImp
package com.majiang.community.service.spring;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.majiang.community.dto.QuestionDTO;
import com.majiang.community.mapper.QuestionMapper;
import com.majiang.community.mapper.UserMapper;
import com.majiang.community.model.Question;
import com.majiang.community.model.User;
import com.majiang.community.service.IQuestionService;
import com.majiang.community.util.CookieUtil;
import com.majiang.community.util.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* @date 2022-04-22
*/
@Service
public class QuestionServiceImp extends ServiceImpl<QuestionMapper,Question> implements IQuestionService {
@Autowired(required = false)
QuestionMapper questionMapper;
@Autowired(required = false)
UserMapper userMapper;
@Override
public List<QuestionDTO> getQuestionList() {
List<QuestionDTO> questionDTOList=new ArrayList<>();
List<Question> questionList = questionMapper.selectList(null);
for(Question question:questionList){
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("fd_account_id", question.getCreator());
User user = userMapper.selectOne(userQueryWrapper);
QuestionDTO questionDTO = new QuestionDTO();
BeanUtils.copyProperties(question, questionDTO);
questionDTO.setUser(user);
questionDTOList.add(questionDTO);
}
return questionDTOList;
}
@Override
public PageUtils getQuestionPage(int current, int size) {
Page page=new Page(current,size);
//查询出所有的问题列表
IPage iPage = questionMapper.selectPage(page, null);
List<Question> questionList= iPage.getRecords();
//
List<QuestionDTO> questionDTOList=new ArrayList<>();
for (Question question:questionList){
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("fd_account_id", question.getCreator());
User user = userMapper.selectOne(userQueryWrapper);
QuestionDTO questionDTO = new QuestionDTO();
BeanUtils.copyProperties(question, questionDTO);
questionDTO.setUser(user);
questionDTOList.add(questionDTO);
}
iPage.setRecords(questionDTOList);
return new PageUtils(iPage);
}
@Override
public PageUtils selectMyQuestion(int current, int size, User user) {
Page page=new Page(current,size);
QueryWrapper<Question> questionQueryWrapper = new QueryWrapper<>();
questionQueryWrapper.eq("creator", user.getFdAccountId());
IPage iPage = questionMapper.selectPage(page, questionQueryWrapper);
return new PageUtils(iPage);
}
@Override
public QuestionDTO getQuestionById(String id) {
Question question = questionMapper.selectById(id);
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("fd_account_id", question.getCreator());
User user = userMapper.selectOne(userQueryWrapper);
QuestionDTO questionDTO = new QuestionDTO();
BeanUtils.copyProperties(question, questionDTO);
questionDTO.setUser(user);
return questionDTO;
}
@Override
public void updateQuestion(QuestionDTO questionDTO) {
Question question=new Question();
BeanUtils.copyProperties(questionDTO, question);
int i = questionMapper.updateById(question);
System.out.println("修改了"+i);
}
@Override
public void deleteQuestion(String id) {
questionMapper.deleteById(id);
}
@Override
public void addQuestion(QuestionDTO questionDTO, HttpServletRequest request) {
String cookieValue = CookieUtil.getCookieValue(request);
QueryWrapper queryWrapper=new QueryWrapper();
queryWrapper.eq("fd_token", cookieValue);
User user = userMapper.selectOne(queryWrapper);
Question question=new Question();
BeanUtils.copyProperties(questionDTO, question);
question.setCreator(user.getFdAccountId());
questionMapper.insert(question);
}
}
profile.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>码匠问题社区</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>-->
<!--<script type="text/javascript" src="/js/jquery.js"></script>-->
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/css/community.css"/>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid" th:replace="navigation::navigation"></div>
</nav>
<div class="container-fluid main">
<div class="row">
<div class="col-md-9 col-md-12 col-sm-12 col-xs-12">
<h2><span class="glyphicon glyphicon-list" th:text="${sectionName}"/></h2>
<hr>
<div class="media" th:each="questionDTO :${myQuestionPage.getList()}">
<div class="media-body">
<a th:href="@{'/question/'+${questionDTO.getId()}}" th:text="${questionDTO.getTitle()}"></a>
<!-- <h4 class="media-heading" th:text="${questionDTO.getTitle()}"></h4>-->
<br>
<span th:text="${questionDTO.tag}"></span><br>
<span class="text-desc">
• <span th:text="${questionDTO.getCommentCount()}"></span> 个评论
• <span th:text="${questionDTO.getLikeCount()}"></span> 次浏览
•<span th:text="${#dates.format(questionDTO.getGmtCreate(),'yyyy-MM-dd')}"></span>发布
</span>
</div>
</div>
<nav aria-label="Page navigation">
<ul class="pagination">
<li th:if="${myQuestionPage.getCurrPage()!=1}">
<a th:href="@{'/profile/'+${section}(current=1,size=${myQuestionPage.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true"><<</span><!--首页-->
</a>
</li>
<li th:if="${myQuestionPage.getCurrPage()!=1}">
<a th:href="@{'/profile/'+${section}(current=${myQuestionPage.getCurrPage()-1},size=${myQuestionPage.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true"><</span><!--上一页-->
</a>
</li>
<li th:each="page:${myQuestionPage.getPageNumber()}" th:class="${myQuestionPage.getCurrPage()==page}?'active' : ''">
<a th:href="@{'/profile/'+${section}(current=${page},size=${myQuestionPage.getPageSize()})}" th:text="${page}"></a>
</li>
<li th:if="${myQuestionPage.getCurrPage()!=myQuestionPage.getTotalPage()}">
<a th:href="@{'/profile/'+${section}(current=${myQuestionPage.getCurrPage()+1},size=${myQuestionPage.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true">></span><!--下一页-->
</a>
</li>
<li th:if="${myQuestionPage.getCurrPage()!=myQuestionPage.getTotalPage()}">
<a th:href="@{'/profile/'+${section}(current=${myQuestionPage.getTotalPage()},size=${myQuestionPage.getPageSize()})}" aria-label="Previous">
<span aria-hidden="true">>></span><!--尾页-->
</a>
</li>
</ul>
</nav>
</div>
<div class="col-md-3 col-md-12 col-sm-12 col-xs-12">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" th:class="${section=='question'}?'active':''">
<a href="/profile/question">我的问题
<span class="badge" th:text="${myQuestionPage.getTotalCount()}"/>
</a>
</li>
<li role="presentation" th:class="${section=='reply'}?'active':''">
<a href="/profile/reply">我的回复</a>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
问题详情
实现类代码上面已展示,这里省略。。。。
引入md
md下载
question.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>码匠问题社区</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>-->
<!--<script type="text/javascript" src="/js/jquery.js"></script>-->
<link rel="stylesheet" href="/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/css/community.css"/>
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
<link rel="stylesheet" href="/css/editormd.min.css">
<link rel="stylesheet" href="/css/editormd.preview.min.css">
<script src="/js/editormd.min.js" type="application/javascript"></script>
<script src="/js/moment.js" type="application/javascript"></script>
<script src="/js/lib/marked.min.js"></script>
<script src="/js/lib/prettify.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid" th:replace="navigation::navigation"></div>
</nav>
<div class="container-fluid main">
<div class="row">
<div class="col-md-9 col-md-12 col-sm-12 col-xs-12">
<br>
<h4 class="media-heading" th:text="${questionDTO.getTitle()}"></h4>
<span class="text-desc">
作者 <span th:text="${questionDTO.getUser().getFdName()}"></span>|
发布于 <span th:text="${#dates.format(questionDTO.getGmtCreate(),'yyyy-MM-dd')}"></span>|
阅读数: <span th:text="${questionDTO.getLikeCount()}"></span>
</span>
<hr>
<!--内容-->
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="question-view">
<textarea style="display:none;" th:text="${questionDTO.getDescription()}"></textarea>
</div>
<script type="text/javascript">
$(function () {
editormd.markdownToHTML("question-view", {});
});
</script>
<hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<!--编辑-->
<a th:href="@{'/publish/'+${questionDTO.id}}" class="community-menu"
th:if="${session.user != null && session.user.fdId == questionDTO.creator}">
<span class="glyphicon glyphicon-edit" aria-hidden="true">编辑</span>
</a>
<span> </span>
<!--删除(TODO)-->
<a th:href="@{'/publish/delete/'+${questionDTO.id}}" class="community-menu"
th:if="${session.user != null && session.user.fdId == questionDTO.creator}">
<span class="glyphicon glyphicon-remove" aria-hidden="true">删除</span>
</a>
</div>
<hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
</div>
<div class="col-md-3 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-12 col-md-12 col-sm-12 col-xs-12">
<h4>发起人</h4>
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object img-rounded" th:src="${questionDTO.getUser().getAvatarUrl()}">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">
<span th:text="${questionDTO.getUser().getFdName()}"></span>
</h4>
</div>
</div>
</div>
<hr class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h4>相关问题</h4>
<ul class="question-related">
<!--<li th:each="related : ${relatedQuestions}">
<a th:href="@{'/question/'+ ${related.id}}" th:text="${related.title}"></a>
</li>-->
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
PublishController
package com.majiang.community.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.majiang.community.dto.QuestionDTO;
import com.majiang.community.mapper.QuestionMapper;
import com.majiang.community.mapper.UserMapper;
import com.majiang.community.model.Question;
import com.majiang.community.model.User;
import com.majiang.community.service.IQuestionService;
import com.majiang.community.util.CookieUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
/**
* @date 2022-04-21
*/
@Controller
public class PublishController {
@Autowired(required = false)
private QuestionMapper questionMapper;
@Autowired(required = false)
private UserMapper userMapper;
@Autowired
private IQuestionService questionService;
@GetMapping("/publish")
public String createQuestion(Model model,
HttpServletRequest request){
String cookieValue = CookieUtil.getCookieValue(request);
if(StrUtil.isEmpty(cookieValue)){
return "index";
}
QuestionDTO questionDTO=new QuestionDTO();
model.addAttribute("questionDTO", questionDTO);
return "publish";
}
@PostMapping("/publish")
public String saveQuestion(@RequestParam(name = "title")String title,
@RequestParam(name="description")String description,
@RequestParam(name = "tag")String tag,
@RequestParam(name = "id",required = false)String id,
HttpServletRequest request,
Model model){
QuestionDTO questionDTO=new QuestionDTO();
questionDTO.setTitle(title);
questionDTO.setDescription(description);
questionDTO.setTag(tag);
if(StrUtil.isNotEmpty(id)){
questionDTO.setId(id);
}
model.addAttribute("questionDTO", questionDTO);
if(StrUtil.isEmpty(title)){
model.addAttribute("error", "标题不能为空");
return "publish";
}
if(StrUtil.isEmpty(description)){
model.addAttribute("error", "问题描述不能为空");
return "publish";
}
if(StrUtil.isEmpty(tag)){
model.addAttribute("error", "标签不能为空");
return "publish";
}
if(StrUtil.isNotEmpty(id)){
questionService.updateQuestion(questionDTO);
}else{
questionService.addQuestion(questionDTO,request);
}
return "redirect:/";
}
/**
* 编辑问题
*/
@GetMapping("publish/{id}")
public String editQuestion(@PathVariable(name = "id")String id,
Model model){
//TODO 鉴定用户是否有权限修改
QuestionDTO questionDTO = questionService.getQuestionById(id);
model.addAttribute("questionDTO",questionDTO);
return "publish";
}
/**
* 删除问题
*/
@GetMapping("publish/delete/{id}")
public String deleteQuestion(@PathVariable(name = "id")String id){
//TODO 鉴定用户是否有权限删除
questionService.deleteQuestion(id);
return "redirect:/profile/question";
}
}
questionService实现类代码上面已展示,这里省略。。。。
publish.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>码匠问题社区</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/css/bootstrap.min.css" />
<link rel="stylesheet" href="/css/community.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
<link rel="stylesheet" href="/css/editormd.min.css">
<link rel="stylesheet" href="/css/editormd.preview.min.css">
<script src="/js/editormd.min.js" type="application/javascript"></script>
<script src="/js/moment.js" type="application/javascript"></script>
<script src="/js/lib/marked.min.js"></script>
<script src="/js/lib/prettify.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid" th:replace="navigation::navigation"></div>
</nav>
<div class="container-fluid main">
<div class="row">
<div class="col-md-9 col-md-12 col-sm-12 col-xs-12">
<h2><span class="glyphicon glyphicon-plus"/>发起</h2>
<hr>
<form action="/publish" method="post">
<input type="hidden" name="id" th:value="${questionDTO.getId()}">
<div class="form-group">
<label for="title">问题标题(简单扼要):</label>
<input type="text" class="form-control" th:value="${questionDTO.getTitle()}" id="title" name="title"
placeholder="问题标题……"
autocomplete="off">
</div>
<div class="form-group" id="question-editor" style="z-index: 2">
<label for="description">问题补充 (必填,请参照右侧提示):</label>
<textarea name="description" id="description" th:text="${questionDTO.description}" style="display:none;"
class="form-control"
cols="30"
rows="10"></textarea>
</div>
<div class="form-group">
<label for="title">添加标签:</label>
<input type="text" class="form-control" th:value="${questionDTO.getTag()}" id="tag" name="tag"
placeholder="问题标题……">
</div>
<div class="container-fluid main ">
<div class="row">
<div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">
<div class="alert alert-danger col-lg-12 col-md-12 col-sm-12 col-xs-12"
th:text="${error}"
th:if="${error != null}">
</div>
</div>
<div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
<button type="submit" class="btn btn-success btn-publish ">
发布
</button>
</div>
</div>
</div>
</form>
</div>
<div class="col-md-3 col-md-12 col-sm-12 col-xs-12">
<h3>问题发起指南</h3>
• 问题标题: 请用精简的语言描述您发布的问题,不超过25字 <br>
• 问题补充: 详细补充您的问题内容,并确保问题描述清晰直观, 并提供一些相关的资料<br>
• 选择标签: 选择一个或者多个合适的标签,用逗号隔开,每个标签不超过10个字<br>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
var editor = editormd("question-editor", {
width: "100%",
height: 350,
path: "/js/lib/",
delay: 0,
watch: false,
placeholder: "请输入问题描述",
imageUpload: true,
imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL: "/file/upload",
});
});
</script>
</body>
</html>
mybatis-plus创建时间和修改时间自动生成
package com.majiang.community.model;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
* @date 2022-04-20
*/
@Data
public class User {
@TableId(value = "fd_id",type = IdType.ID_WORKER_STR)
private String fdId;
/**
* 姓名
*/
private String fdName;
/**
* 登录名
*/
private String login;
/**
* 账号id
*/
private String fdAccountId;
/**
* 授权标识
*/
private String fdToken;
/**
* 图片地址
*/
private String avatarUrl;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)//INSERT代表只在插入时填充
private Long gmtCreateTime;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)// INSERT_UPDATE 首次插入、其次更新时填充(或修改)
private Long gmtAlterTime;
}
创建MetaObjectHandler接口实现类即可,不用特意调用
package com.majiang.community.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
/**
* @date 2022-04-29
*/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
//属性名称,不是字段名称
if(metaObject.hasSetter("gmtCreate")){
this.setFieldValByName("gmtCreate", System.currentTimeMillis(), metaObject);
}
if(metaObject.hasSetter("gmtModified")){
this.setFieldValByName("gmtModified", System.currentTimeMillis(), metaObject);
}
if(metaObject.hasSetter("gmtCreateTime")){
this.setFieldValByName("gmtCreateTime", System.currentTimeMillis(), metaObject);
}
if(metaObject.hasSetter("gmtAlterTime")){
this.setFieldValByName("gmtAlterTime", System.currentTimeMillis(), metaObject);
}
}
@Override
public void updateFill(MetaObject metaObject) {
if(metaObject.hasSetter("gmtModified")){
this.setFieldValByName("gmtModified", System.currentTimeMillis(), metaObject);
}
if(metaObject.hasSetter("gmtAlterTime")){
this.setFieldValByName("gmtAlterTime", System.currentTimeMillis(), metaObject);
}
}
}