由于html中原生的textarea功能太弱,无法完成一些字体,颜色等功能,因此我们在开的时候经常会使用富文本框
UEditor, CKEditor,wangEditor 市面用得比较多的富文本框
使用是的wangEditor,要学习的话可以去看它的官网 -> http://www.wangeditor.com/
主要是完成文本框的展示
...
var E = window.wangEditor
var editor = new E('#intro');
var $text1 = $('#txtIntro');
editor.customConfig.onchange = function(html) {
// 监控变化,同步更新到 textarea
$text1.val(html);
}
editor.create();
// 初始化 文本编辑器的内容
editor.txt.html('${img.intro}')
// 初始化对应的内容
$text1.val(editor.txt.html());
删除数据的时候同时也要删除相应的文件(图片)
file.delete()
@RequestMapping("/delete")
public String delete(Integer id,HttpServletRequest req){
//注意:在咱们删除功能前还要先把图片删除了
//1.拿到咱们的Image数据
Images images = imageService.findOne(id);
if(images!=null){
//2.拿到真实的路径
String realPath = req.getServletContext().getRealPath("");
//3.拿到文件路径
String filePath = images.getStorepath();
//4.获取到文件
File file = new File(realPath+filePath);
//5.删除文件
file.delete();
}
imageService.delete(id);
return "redirect:/images/query";
}
active
">
${img.intro}
/**
* 分页对象
* @author Administrator
*
*/
public class PageList {
//当前页 -> 前台传过来
private int currentPage = 1;
//每页条数 -> 前台传过来/自己定义
private int pageSize = 10;
//首页(第一页)
private int firstPage = 1;
//上一页 计算出来 currentPage>1?currentPage-1:1
private int prevPage;
//下一页 计算出来 currentPage 数据库中查询出来
private int totalCount;
//当前页的数据 -> 数据库中查询出来
private List data = new ArrayList<>();
public PageList(){}
/**
* @param currentPage:前台传过来
* @param pageSize:前台传过来
* @param totalCount:数据库中查询
* @param data:数据库中查询
*/
public PageList(int currentPage, int pageSize, int totalCount, List data) {
this.currentPage = currentPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
this.data = data;
//计算上一页 当前页>1 ? 当前页-1 : 1
this.prevPage = this.currentPage>1 ? this.currentPage-1 : 1;
//计算总页数 总条数%每页条数==0? 总条数/每页条数:总条数/每页条数+1
this.totalPage = this.totalCount%this.pageSize==0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
this.lastPage = this.totalPage; //最后一页就是总页数
//计算下一页 当前页<总页数?当前页+1:总页数;
this.nextPage = this.currentPage
public class SqlCondition {
//当前页
private int currentPage = 1;
//每页条数
private int pageSize = 10;
//getter,setter省略
}
/**
* 最后返回的是PageList对象,里面都要有值
* PageList(int currentPage, int pageSize, int totalCount, List data)
*/
@Override
public PageList queryAll(SqlCondition condition) {
//①.拿到当前页与每页条数
int currentPage = condition.getCurrentPage();
int pageSize = condition.getPageSize();
//一.查询总条数
//1.1 准备查询总条数的sql
String sql = "select count(*) from t_image";
//1.2执行sql拿到总条数
Integer totalCount = jdbcTemplate.queryForObject(sql, Integer.class);
//二.查询当前页的数据
//2.1 计算当前页是从第几条数据开始的
int beginIndex = (currentPage-1) * pageSize;
//2.2 准备相应的SQL
String dataSql = "select * from t_image limit "+beginIndex+","+pageSize;
//2.3 执行查询功能
List data= jdbcTemplate.query(dataSql, new BeanPropertyRowMapper<>(Images.class));
//三.创建PageList对象并且返回
PageList pageList = new PageList(currentPage,pageSize,totalCount,data);
return pageList;
}
@RequestMapping("/query")
public String query(SqlCondition condition,Model model){
model.addAttribute("pageList",imageService.queryAll(condition));
return "main";
}
...