springboot使用PageHelper分页插件和验证码功能

 时间:2024-10-16 05:39:13

在做web项目的时候,一般都会有浏览器显示一行行数据的问题,传统的代码也可以实现分页,但是很繁琐,今天给大家说一下如何使用PageHelper分页插件轻松实现分页效果。在登录页面一般都会有输入验证码功能,在这一起跟大家说一下。

springboot使用PageHelper分页插件和验证码功能

工具/原料

电脑

eclipse等其他软件开发工具

使用springboot框架开发的工程项目

集成PageHelper分页插件

1、双击打开pom文件

springboot使用PageHelper分页插件和验证码功能

3、编写分页bean类,注意:这个类一定要放在springboot启动类所在位置的平级或子级的包中,保证能springboot扫描到。import java.util.Properties;import org.apache.ibatis.plugin.Interceptor;import org.mybatis.spring.SqlSessionFactoryBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import com.github.pagehelper.PageHelper;@Configurationpublic class PageHelperBean { @Bean PageHelper pageHelper(){ //分页插件 PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("reasonable", "true"); properties.setProperty("supportMethodsArguments", "true"); properties.setProperty("returnPageInfo", "check"); properties.setProperty("params", "count=countSql"); pageHelper.setProperties(properties); //添加插件 new SqlSessionFactoryBean().setPlugins(new Interceptor[]{pageHelper}); return pageHelper; }}

springboot使用PageHelper分页插件和验证码功能

5、在controller层调用分页在这要调用两个service,一个是上一步骤的分页查询,还有就是要通过service连接dao层连接数据库,count出总条数。最后returnPageBean<实体类> 就可以了,通过@ResponseBody可以直接把数据转换成json格式的字符串,被前台解析识别,显示在页面

springboot使用PageHelper分页插件和验证码功能

集成kaptcha验证码

1、打开pom文件,添加如下的依赖:<鲐扼敲行!--https://mvnrepository.com/artifact/com.github.penggle/kaptc茑霁酌绡ha--><dependency><groupId>com.github.penggle</groupId><artifactId>kaptcha</artifactId><version>2.3.2</version></dependency>

2、在resources中创建一个mykaptcha.xml文件

springboot使用PageHelper分页插件和验证码功能

7、验证码验证是否正确:表单提交到后台,与后台存到session中的验证码信息做比较

springboot使用PageHelper分页插件和验证码功能
  • MyBatis如何使用PageHelper插件实现分页查询
  • 如何通过MyBatis PageHelper插件实现分页查询
  • mybatis分页插件-pagehelper的使用
  • 很好用的分页插件pageHelper
  • 谷歌浏览器插件xpath helper 的安装和使用
  • 热门搜索
    文竹叶子发黄怎么办 中短发怎么扎好看 微信英语怎么说 数学符号怎么打出来 qq群解散了怎么恢复 堵车怎么发朋友圈搞笑 word怎么删除分页符 吉他怎么换弦 建设银行怎么查开户行 工作自我评价怎么写