您的位置:首页 > 教育 > 培训 > 公司简介ppt介绍范本_深圳相框制作_2345浏览器网址_西安网站制作价格

公司简介ppt介绍范本_深圳相框制作_2345浏览器网址_西安网站制作价格

2025/5/19 10:35:04 来源:https://blog.csdn.net/c_yanxin_ru/article/details/145653061  浏览:    关键词:公司简介ppt介绍范本_深圳相框制作_2345浏览器网址_西安网站制作价格
公司简介ppt介绍范本_深圳相框制作_2345浏览器网址_西安网站制作价格
前言:

通过实践而发现真理,又通过实践而证实真理和发展真理。从感性认识而能动地发展到理性认识,又从理性认识而能动地指导革命实践,改造主观世界和客观世界。实践、认识、再实践、再认识,这种形式,循环往复以至无穷,而实践和认识之每一循环的内容,都比较地进到了高一级的程度。

正片

我们目前的分页,还是静态的,只能根据方法中的参数进行查询,3.0版本将向动态发展

在Spring Security的动态认证时,他们提供了一个方法可以事实拿去表单用户名,这里我们有办法实时获取参数吗?

答案是有的——通过Spring Web框架,实时获取参数

在这里,我们先照着上一个版本的分页写完

XML版本 3.0

第一步:增加实体类(连接数据库与服务端的桥梁)

第二步:增加Mapper接口

第三步:增加XML文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="具体mapper层路径,精确到文件名">
​
</mapper>

tip:Mapper和XML保证路径相同,文件名相同

第四步:增加Service类

第一步:创建一个接口类 interface 接口名

第二步:创建一个实现类 实现类名 implements 接口名

第五步:增加Controller类(返回经处理过的数据)

第六步:增加Configuration类

@Configuration
@MapperScan(basePackages = "mapper层")
public class ApplicationConfig {
​
}

第七步:测试

2.0中,我们完成了第三步就去验证了,这次我们先补全模板

package org.example.mybatis.servlet;import org.example.mybatis.Mapper.TestMapper;import java.util.List;public interface TestServlet {List<TestMapper>  SelectLimit(int into, int Max);    //相对于复制了一遍TestMapper}

实现接口

package org.example.mybatis.servlet.Imp;import jakarta.annotation.Resource;
import org.example.mybatis.Mapper.TestMapper;
import org.example.mybatis.servlet.TestServlet;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class TestServletImp implements TestServlet {@Resourceprivate TestMapper testMapper;@Overridepublic List<TestMapper> SelectLimit(int into, int Max) {return  testMapper.SelectLimit(into, Max);}
}

具体业务逻辑写这

第五步:controller层

package org.example.mybatis.controller;import org.example.mybatis.Mapper.TestMapper;
import org.example.mybatis.servlet.TestServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestControllerpublic class test {@AutowiredTestServlet testServlet;@GetMapping("test")public String SelectLimit(){List<TestMapper> testMappers = testServlet.SelectLimit(0, 4);return "打印成功" + testMappers;}
}

第六步:添加配置

package org.example.mybatis;import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan(basePackages = "org.example.mybatis.Mapper")
public class MybatisApplication {public static void main(String[] args) {SpringApplication.run(MybatisApplication.class, args);}
}

这个注解当我们只有一个mapper的时候可以不需要添加,多个的时候一定要加,因为他可以自动扫描,省去你挨个添加@Mapper的时间

第七步测试

现在首要的目的是将参数改为从前台获取,这里可以使用MVC的一个机制

@RestController
public class test {@AutowiredTestServlet testServlet;@GetMapping("test")public String SelectLimit(int into,int Max){List<TestMapper> testMappers = testServlet.SelectLimit(into,Max);return "打印成功" + testMappers;}
}

添加参数,调用参数

动态的分页,也就是在控制层中添加参数

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com