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

江苏商城网站建设传奇网页游戏网

江苏商城网站建设,传奇网页游戏网,织梦网站图片怎么修改,展厅设计图片这篇需结合 Mybatis XML 配置文件那一篇博客一起看 工作中尽量避免使用多表查询,尤其是对性能要求非常高的项目 我们之前建了个用户表(代码在Mybatis XML配置文件那篇博客里),这次再建一个文章表,代码如下 : -- 创建⽂章表 DROP TABLE IF EXISTS articleinf…这篇需结合 Mybatis XML 配置文件那一篇博客一起看 工作中尽量避免使用多表查询,尤其是对性能要求非常高的项目 我们之前建了个用户表(代码在Mybatis XML配置文件那篇博客里),这次再建一个文章表,代码如下 : -- 创建⽂章表 DROP TABLE IF EXISTS articleinfo; CREATE TABLE articleinfo (id INT PRIMARY KEY auto_increment,title VARCHAR ( 100 ) NOT NULL,content TEXT NOT NULL,uid INT NOT NULL,delete_flag TINYINT ( 4 ) DEFAULT 0 COMMENT 0-正常, 1-删除,create_time DATETIME DEFAULT now(),update_time DATETIME DEFAULT now() ) DEFAULT charset utf8mb4; -- 插⼊测试数据 INSERT INTO articleinfo ( title, content, uid ) VALUES( Java, Java正⽂, 1 ); 如何根据文章ID,获取作者的名字和年龄呢?( ta 是表 articleInfo , tb 是表 userinfo ) select ta.*,tb.username,tb.age from articleinfo ta left join userinfo tb on ta.uid tb.id where ta.id 1; 这样就能拿到文章 id 为1的作者的相关信息了 接下来我们就要跟java联系起来了 先创建一个 java 类,写与 articleinfo 表的字段一一映射的java对象 package com.example.mybatisdemo.model;import lombok.Data;import java.util.Date;Data public class ArticleInfo {//文章相关信息private Integer id;private String title;private String content;private Integer uid;private Integer deleteFlag;private Date createTime;private Date updateTime; } 然后再创建一个接口,名为ArticleInfoMapper package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.ArticleInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select;Mapper public interface ArticleInfoMapper {Select( select ta.*,tb.username,tb.age from articleinfo ta left join userinfo tb on ta.uid tb.id where ta.id #{id})ArticleInfo selectArticleAndUserById(Integer articleId);} 然后右键,Generate,test,勾选 selectArticleAndUserById ,ok,补充代码 package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.model.ArticleInfo; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import static org.junit.jupiter.api.Assertions.*;Slf4j SpringBootTest class ArticleInfoMapperTest {Autowiredprivate ArticleInfoMapper articleInfoMapper;Testvoid selectArticleAndUserById() {ArticleInfo articleInfo articleInfoMapper.selectArticleAndUserById(1);log.info(articleInfo.toString());} } 成功  但是因为 ArticleInfo 并没有 username 和 age ,所以返回对象为 ArticleInfo 的时候是无法返回 username 和 age 的 所以我们就需要在类 ArticleInfo 里面添加 username 和 age package com.example.mybatisdemo.model; import lombok.Data; import java.util.Date; Data public class ArticleInfo {//文章相关信息private Integer id;private String title;private String content;private Integer uid;private Integer deleteFlag;private Date createTime;private Date updateTime;//用户相关信息private String username;private Integer age; } 再次运行就能拿到 username 和 age 了
http://www.huolong8.cn/news/251333/

相关文章:

  • 企业网站模板下载价格多少seo数据统计分析工具有哪些
  • 网站开发实战教程图片生成器网站
  • 帝国建站程序天津网站制作公司哪家好
  • python 直播网站开发2022最旺公司名称
  • 网站的查询功能是怎样做的公明网站建设
  • 怎么做网站网页归档公众号后台登录
  • 忘了网站链接怎么做网站建设的开发方式知乎
  • 蒙山县网站建设石家庄做网站好的网络技术有限公司
  • 做网站的又营业执照的吗工地模板多少钱一张
  • 网站底部友情链接代码吉首网络推广
  • 网站死了怎么办洛可可设计公司好进吗
  • 饭店网站建设策划方案WordPress免费自动采集
  • 旅游网站如何做手机网站模板大全
  • 商业网站在规划与设计时应着重考虑哪些因素网站开发范围
  • 网页架构人才培训中心seo实战密码第四版
  • 如何做自动网站网站建设 个人
  • 广州网站制作网站建设优化推广哈尔滨
  • 中国建设银行网站e路wordpress dux 高亮
  • 做网站图片像素o2o指的是什么
  • 网站织梦如何让会员注册h5响应式网站建设代理
  • 哪个网站可以付费做淘宝推广昌邑网页设计
  • 如何建手机销售网站wordpress注册链接插件
  • wordpress div广州seo网络培训课程
  • 顺义顺德网站建设建设银行网站会员登陆
  • 个体工商户能网站备案吗自己做网站挂广告
  • 做的比较好的电商网站wordpress+悬浮按钮
  • 制作网站的公司还能赚钱吗微信微博网站建设意见书
  • 怎么做直播室的网站sdcms网站建设模板
  • 网站做系统叫什么名字广州网站制作后缀
  • 网站一个多少钱颍州网站建设