当前位置: 首页 > news >正文

建设工程教育网站论坛wordpress无法跳转正确页面

建设工程教育网站论坛,wordpress无法跳转正确页面,建设网站要服务器吗,直播平台网站开发参考资料 Java 基础 - 泛型机制详解路人甲-Java泛型专题 目录一. 通用Mapper1.1 实体类1.2 Mapper基类1.3 自定义接口1.4 抽象基类Service1.5 调用二. session和bean的获取一. 通用Mapper 1.1 实体类 ⏹ Accessors(chain true): 允许链式调用 import lombok.Data; import …参考资料 Java 基础 - 泛型机制详解路人甲-Java泛型专题 目录一. 通用Mapper1.1 实体类1.2 Mapper基类1.3 自定义接口1.4 抽象基类Service1.5 调用二. session和bean的获取一. 通用Mapper 1.1 实体类 ⏹ Accessors(chain true): 允许链式调用 import lombok.Data; import lombok.experimental.Accessors;import java.math.BigDecimal;Data Accessors(chain true) public class TagEntity {private BigDecimal id;private String name; }1.2 Mapper基类 ⏹ 该接口中定义了共通的增删改查方法 因为要保证基类的通用性使用泛型可以保证能使用任何类型的实体类 import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.math.BigDecimal;public interface BaseMapperT {/*** 返回表中的数据量* * param tableName 表名* return 总数量*/Select( select count(*) from ${tableName} )BigDecimal getCount(Param(tableName) String tableName);/*** 插入数据* * param entity entity* return int 更新件数*/int insert(T entity);/*** 更新数据* * param entity entity* return int 更新件数*/int updateByPrimaryKey(T entity);/*** 删除数据* * param entity entity* return int 删除件数*/int deleteByPrimaryKey(T entity); }1.3 自定义接口 ⏹ 自定义接口继承基类Mapper TagGenericMapper接口继承了BaseMapper接口,也就有了其所有的方法 public interface TagGenericMapper extends BaseMapperTagEntity {// 定义独有的,非共通的方法 }⏹ xml中的insert方法对应着基类Mapper中的insert接口 ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.jmw.mapper.TagGenericMapper!-- 插入数据 --insert idinsert parameterTypejava.util.MapINSERT INTOt_tag(id, name)VALUES (#{id}, #{name})/insert!-- 更新数据 --!-- 删除数据 --!-- 查询数据 -- /mapper1.4 抽象基类Service import org.springframework.beans.factory.annotation.Autowired;public abstract class BaseServiceAbstractT {// ❗❗❗共通的基类Mapper,此处一定不能使用java的Resource来注入,否则失败Autowiredprotected BaseMapperT baseMapper;// 插入int insert(T entity) {int count 0;try {count baseMapper.insert(entity);} catch (Exception ex) {// 模拟打印logSystem.out.println(程序异常,异常的原因是: ex.getMessage());}return count;}// 更新int update(T entity) {int count 0;try {count baseMapper.updateByPrimaryKey(entity);} catch (Exception ex) {// 模拟打印logSystem.out.println(程序异常,异常的原因是: ex.getMessage());}return count;}// 删除int delete(T entity) {int count 0;try {count baseMapper.deleteByPrimaryKey(entity);} catch (Exception ex) {// 模拟打印logSystem.out.println(程序异常,异常的原因是: ex.getMessage());}return count;} }1.5 调用 import org.springframework.stereotype.Service; import org.springframework.boot.CommandLineRunner; import javax.annotation.Resource; import java.math.BigDecimal;Service public class TagService extends BaseServiceAbstractTagEntity implements CommandLineRunner {Resourceprivate TagGenericMapper mapper;Overridepublic void run(String... args) throws Exception {this.init();}public void init() {// 查询指定表中的数据数量BigDecimal count mapper.getCount(t_tag);System.out.println(count); // 5// 准备要插入数据TagEntity tagEntity new TagEntity();tagEntity.setId(BigDecimal.ONE).setName(乌班图);// 通过抽象类中的方法向Tag表中插入数据int result this.insert(tagEntity);System.out.println(result); // 1} }⏹ 流程示意图 二. session和bean的获取 ⏹ 定义一个基类Controller使用泛型将IOC容器和session中获取到的数据转换为对应的实体类 import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.util.ObjectUtils;import javax.servlet.http.HttpSession;public abstract class BaseControllerAbstract implements ApplicationContextAware {private static ApplicationContext applicationContext;// 注入session对象Autowiredprivate HttpSession session;Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {BaseControllerAbstract.applicationContext applicationContext;}// 根据名称获取beanSuppressWarnings(unchecked)protected T T getBean(String name) throws BeansException {// 直接将Bean转换为对应的类型return (T) applicationContext.getBean(name);}// 根据class获取beanprotected T T getBean(ClassT clazz) throws BeansException {return applicationContext.getBean(clazz);}// 设置sessionprotected void setSession(Object data) {session.setAttribute(data.getClass().getSimpleName(), data);}// 获取sessionSuppressWarnings(unchecked)protected T T getSession(Class ? clazz) {Object sessionINfo session.getAttribute(clazz.getSimpleName());if (ObjectUtils.isEmpty(sessionINfo)) {return null;}// 从session中获取到的数据是一个Object类型的数据,使用泛型将其转换为指定的类型return (T) sessionINfo;} }⏹因为使用了泛型所以获取IOC容器中的Bean和session中数据的时候无需进行类型转换 import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView;import java.math.BigDecimal;Controller RequestMapping(/ztest) public class ZTestController extends BaseControllerAbstract {GetMapping(/init)public ModelAndView init() {// 向session中放入数据TagEntity tagEntity new TagEntity();tagEntity.setId(BigDecimal.ONE).setName(tag);this.setSession(tagEntity);ModelAndView modelAndView new ModelAndView();modelAndView.setViewName(ZTest);return modelAndView;}PostMapping(/test)public ResponseEntityVoid test() throws Exception {// 获取Bean对象TagService tag1 this.getBean(tagService);System.out.println(tag1);TagService tag2 this.getBean(TagService.class);System.out.println(tag2);// 从session中获取entity数据TagEntity sessionEntity this.getSession(TagEntity.class);System.out.println(sessionEntity);return ResponseEntity.noContent().build();} }
http://www.w-s-a.com/news/43441/

相关文章:

  • 网站开发用哪些技术seo是什么意思为什么要做seo
  • 网站会动的页面怎么做的与网站建设有关的招标文件
  • 公司网站如何做seowordpress付费资源
  • 福田做商城网站建设哪家公司便宜点WordPress安装子目录
  • 南京建设交易中心网站wordpress 拼车
  • 上海今天发生的重大新闻5条河南网站seo费用
  • 广东深圳最新情况临安网站seo
  • 华为快速建站女人做春梦网站
  • 建外贸网站费用手机排行榜zol
  • 长治网站制作的网站做网站要什么知识条件
  • discuz 做门户网站wordpress怎么添加图片不显示图片
  • 东营网站建设方案范文百度应用搜索
  • 网站 常见推广js代码放wordpress哪里
  • 靖江网站开发徐州住房和城乡建设局网站
  • 南宁网站建设公司如何为老板打造网站赚钱的wordpress optimizer
  • 做微商好还是开网站好网站网络推广
  • 网站建设岗位所需技能泊头网站优化
  • 企业网站建设是什么网络营销岗位介绍
  • 网站做cdn怎么弄昆明网站seo报价
  • 拖拽网站如何建立微网站
  • 网站网站做代理微信群卖房卡南宁建站模板大全
  • 网络公司怎么优化网站百度快速排名技术培训教程
  • 建e室内设计网 周婷站长工具seo综合查询源码
  • 塔式服务器主机建网站定制美瞳网站建设
  • 网站是先解析后备案吗永久免费网站模板
  • wordpress站点演示php根据ip 跳转网站
  • 东莞市凤岗建设局网站网站开发有哪些职位
  • 企业网站手机版模板免费下载辣条网站建设书
  • 南昌网站建设维护vc 做网站源码
  • 网站动态logo怎么做织梦移动端网站怎么做