SpringBoot-CRUD+分页与网页灰化(附加一个好玩的小玩意)
Posted Empirefree
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot-CRUD+分页与网页灰化(附加一个好玩的小玩意)相关的知识,希望对你有一定的参考价值。
SpringBoot总共有3种CRUD+分页:JPA,Mybatis,SQL lite,个人觉得mybatis用起来最方便。
学习教程:https://how2j.cn/k/springboot/springboot-mybatis-crud-pagination/1651.html#nowhere
1jar包
1 <!-- 分页支持-->
2 <dependency>
3 <groupId>com.github.pagehelper</groupId>
4 <artifactId>pagehelper</artifactId>
5 <version>4.1.6</version>
6 </dependency>
2.PageHelper函数支持
package com.empirefree.springboot.config;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.pagehelper.PageHelper;
/**
* @author Empirefree 胡宇乔:
* @version 创建时间:2020年4月6日 上午11:54:04
*/
@Configuration
public class PageHelperConfig {
@Bean
public PageHelper pageHelper(){
PageHelper pageHelper = new PageHelper();
Properties p = new Properties();
p.setProperty("offsetAsPageNum", "true");
p.setProperty("rowBoundsWithCount", "true");
p.setProperty("reasonable", "true");
pageHelper.setProperties(p);
return pageHelper;
}
}
3.Mapper中的CRUD方法:个人建议这里可以自己写个代码生成器,这样方便以后开发springboot项目
1 package com.empirefree.springboot.mapper;
2 /**
3 * @author Empirefree 胡宇乔:
4 * @version 创建时间:2020年3月18日 下午2:15:10
5 */
6 import java.util.List;
7
8 import org.apache.ibatis.annotations.Delete;
9 import org.apache.ibatis.annotations.Insert;
10 import org.apache.ibatis.annotations.Mapper;
11 import org.apache.ibatis.annotations.Select;
12 import org.apache.ibatis.annotations.Update;
13
14 import com.empirefree.springboot.pojo.Category;
15
16 @Mapper
17 public interface CategoryMapper {
18
19 //找到所有对象
20 @Select("select * from category_ ")
21 List<Category> findAllCategory();
22
23 //找到所有对象
24 @Select("select * from category_ " + "where id like concat (\'%\',#{id},\'%\') or name like concat (\'%\',#{name},\'%\')")
25 List<Category> findBySomeCategory(Category category);
26
27 // 根据一个抽象对象找到所有符合要求的对象
28 @Select("select * from "+ "category_" +" where id = #{id}")
29 public Category findById(Integer id);
30 /************************可以使用代码生成器****************************************/
31 @Insert(" insert into category_ ( name ) values (#{name}) ")
32 public int save(Category category);
33
34 @Delete(" delete from category_ where id= #{id} ")
35 public void delete(int id);
36
37 @Update("update category_ set name=#{name} where id=#{id} ")
38 public int update(Category category);
39 }
4:Contrller层:注意,这里要使用mybatis的findAll(),不能使用JPA的findALL();
package com.empirefree.springboot.web;
/**
* @author Empirefree 胡宇乔:
* @version 创建时间:2020年3月17日 下午8:01:04
*/
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.empirefree.springboot.dao.CategoryDAO;
import com.empirefree.springboot.mapper.CategoryMapper;
import com.empirefree.springboot.pojo.Category;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Controller
public class CategoryController {
@Autowired
CategoryDAO categoryDAO;
@Autowired
CategoryMapper categoryMapper;
@RequestMapping("/listCategory")
public String listCategory(Model m, @RequestParam(value = "start", defaultValue = "0") int start,@RequestParam(value = "size", defaultValue = "5") int size) throws Exception {
// List<Category> cs = categoryDAO.findAll();
// PageHelper.startPage(start,size,"id desc");
PageHelper.startPage(start,size,"id");
List<Category> cs = categoryMapper.findAllCategory();
// Category category = new Category();
// category.setName("牛逼");
// List<Category> cs = categoryMapper.findBySomeCategory(category);
PageInfo<Category> page = new PageInfo<>(cs);
m.addAttribute("page", page);
// m.addAttribute("cs", cs);
return "listCategory";
}
@RequestMapping("/addCategory")
public String listCategory(Category c) throws Exception {
categoryMapper.save(c);
return "redirect:listCategory";
}
@RequestMapping("/deleteCategory")
public String deleteCategory(Category c) throws Exception {
categoryMapper.delete(c.getId());
return "redirect:listCategory";
}
@RequestMapping("/updateCategory")
public String updateCategory(Category c) throws Exception {
categoryMapper.update(c);
return "redirect:listCategory";
}
@RequestMapping("/editCategory")
public String listCategory(int id,Model m) throws Exception {
Category c= categoryMapper.findById(id);
m.addAttribute("c", c);
return "editCategory";
}
}
5:网页灰度化(祭奠逝去的抗击肺炎英雄们):主要函数就是:filter
html {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
}
listCategory.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
4
5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6 <html>
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 <title>Insert title here</title>
10 <style>
11 html {
12 -webkit-filter: grayscale(100%);
13 -moz-filter: grayscale(100%);
14 -ms-filter: grayscale(100%);
15 -o-filter: grayscale(100%);
16 filter: grayscale(100%);
17 filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
18 }
19 </style>
20
21 </head>
22 <body>
23 <div style="width:500px;margin:20px auto;text-align: center">
24 <table align=\'center\' border=\'1\' cellspacing=\'0\'>
25 <tr>
26 <td>id</td>
27 <td>name</td>
28 <td>编辑</td>
29 <td>删除</td>
30 </tr>
31 <c:forEach items="${page.list}" var="c" varStatus="st">
32 <tr>
33 <td>${c.id}</td>
34 <td>${c.name}</td>
35 <td><a href="editCategory?id=${c.id}">编辑</a></td>
36 <td><a href="deleteCategory?id=${c.id}">删除</a></td>
37 </tr>
38 </c:forEach>
39
40 </table>
41 <br>
42 <div>
43 <a href="?start=1">[首 页]</a>
44 <a href="?start=${page.pageNum-1}">[上一页]</a>
45 <a href="?start=${page.pageNum+1}">[下一页]</a>
46 <a href="?start=${page.pages}">[末 页]</a>
47 </div>
48 <br>
49 <form action="addCategory" method="post">
50
51 name: <input name="name"> <br>
52 <button type="submit">提交</button>
53
54 </form>
55 </div>
56 </body>
57 </html>
---------------------------------------C语言爆破好友消息(图片,文字,文件都可以)------------------------------------------------------------
C语言函数如下:(VS studio环境)
1 #include <stdio.h>
2 #include <Windows.h>
3 // Empirefree 胡宇乔
4 int main()
5 {
6 int i;
7 char name[100]; //使用之前要先复制要轰炸的内容
8 printf("输入你要轰炸的对象名称:");
9 scanf_s("%s", &name, 40);
10 printf("输入你要轰炸的次数:");
11 scanf_s("%d", &i);
12 HWND H = FindWindow(0,name); //找到对话窗口
13 while (i-- > 0)
14 {
15 SendMessage(H, WM_PASTE, 0, 0); //黏贴内容
16 SendMessage(H, WM_KEYDOWN, VK_RETURN, 0); //回车发送
17 }
18 }
以上是关于SpringBoot-CRUD+分页与网页灰化(附加一个好玩的小玩意)的主要内容,如果未能解决你的问题,请参考以下文章