-
2017-05-12 14:55:19
多表联查,有相同的字段,同名字段会覆盖前一字段的值,设置别名时,hibernate不能识别
在连接mysql数据库时添加useOldAliasMetadataBehavior=true
例如:jdbc.url=jdbc:mysql://192.168.122.5:3306/teamtodo?autoReconnect=true&characterEncoding=utf-8&useSSL=true&useOldAliasMetadataBehavior=true
更多相关内容 -
thinkphp多表查询两表有重复相同字段的完美解决方法
2020-12-18 12:46:17框架:thinkphp 版本:3.2.3 内容:查询语句 解决问题:重复字段问题 $Data = M('a')->where($where) ...以上就是小编为大家带来的thinkphp多表查询两表有重复相同字段的完美解决方法的全部内容了,希望对大家 -
多表联查两张表中所取得字段相同怎么办?
2021-12-17 10:22:24第一张表格的结构 第二章表格的结构 所需要得到的页面展示效果 ...原本的sql:select asset.name,device...由于需要得到两个表相同字段的内容,可以采用前端分析展示 更改后的sql: SELECT name,type,ip FR...第一张表格的结构
第二章表格的结构
所需要得到的页面展示效果
原本的sql: select asset.name,device_type.name,asset.ip from asset LEFT JOIN device_type on asset.type=device_type where asset.type=device_type.type
由于需要得到两个表相同字段的内容,可以采用前端分析展示
更改后的sql:
SELECT name,type,ip FROM asset
JS部分
var pageCurr; var form; $(function () { layui.use('table', function () { var table = layui.table; form = layui.form; tableIns = table.render({ elem: '#getMonitor', url: '/home/findMonitor', method: 'get', //默认:get请求 cellMinWidth: 80, page: true, request: { pageName: 'pageNum', //页码的参数名称,默认:pageNum limitName: 'pageSize' //每页数据量的参数名,默认:pageSize }, // parseData:function (res){ // console.log(res); // return{ // "code":0, // "msg":"", // "count":1000, // "data":res // } // }, response:{ statusName: 'code', //数据状态的字段名称,默认:code statusCode: 200, //成功的状态码,默认:0 countName: 'totals', //数据总数的字段名称,默认:count dataName: 'list' //数据列表的字段名称,默认:data }, cols: [[ {field: 'name', title: '设备名称', align: 'center'} , {field: 'type', title: '设备类型', align: 'center'} , {field: 'ip', title: '设备IP', align: 'center'} ]], done: function (res, count) { $("[data-field='level']").children().each(function () { if ($(this).text() == '紧急') { $(this).val('紧急').css("color", '#FF0000') } else if ($(this).text() == '重要') { $(this).val('重要').css("color", '#FF4500') } else if ($(this).text() == '次要') { $(this).val('次要').css("color", '#FF7F50') } else if ($(this).text() == '一般') { $(this).val('一般').css("color", '#FFA07A') } else if ($(this).text() == '告知') { $(this).val('告知').css("color", '#FFFF00') } }); $("[data-field='type']").children().each(function () { if ($(this).text() == 'DCD') { $(this).text('网络安全监测装置') } else if ($(this).text() == 'DB') { $(this).text('数据库') } else if ($(this).text() == 'IDS') { $(this).text('入侵检测系统') } else if ($(this).text() == 'AV') { $(this).text('防病毒系统') } else if ($(this).text() == 'VEAD') { $(this).text('纵向加密装置') } else if ($(this).text() == 'SW') { $(this).text('交换机') } else if ($(this).text() == 'SVR') { $(this).text('服务器') } else if ($(this).text() == 'BID') { $(this).text('横向方向隔离装置') } else if ($(this).text() == 'FID') { $(this).text('横向正向隔离装置') } else if ($(this).text() == 'FW') { $(this).text('防火墙') } }); } }); }) }) function replaceDoc() { $(function () { layui.use('table', function () { var table = layui.table; form = layui.form; tableIns = table.render({ elem: '#getMonitor', url: '/home/findMonitor', method: 'get', //默认:get请求 cellMinWidth: 80, page: true, request: { pageName: 'pageNum', //页码的参数名称,默认:pageNum limitName: 'pageSize' //每页数据量的参数名,默认:pageSize }, // parseData:function (res){ // console.log(res); // return{ // "code":0, // "msg":"", // "count":1000, // "data":res // } // }, response:{ statusName: 'code', //数据状态的字段名称,默认:code statusCode: 200, //成功的状态码,默认:0 countName: 'totals', //数据总数的字段名称,默认:count dataName: 'list' //数据列表的字段名称,默认:data }, cols: [[ {field: 'name', title: '设备名称', align: 'center'} , {field: 'type', title: '设备类型', align: 'center'} , {field: 'ip', title: '设备IP', align: 'center'} ]], done: function (res, count) { $("[data-field='level']").children().each(function () { if ($(this).text() == '紧急') { $(this).val('紧急').css("color", '#FF0000') } else if ($(this).text() == '重要') { $(this).val('重要').css("color", '#FF4500') } else if ($(this).text() == '次要') { $(this).val('次要').css("color", '#FF7F50') } else if ($(this).text() == '一般') { $(this).val('一般').css("color", '#FFA07A') } else if ($(this).text() == '告知') { $(this).val('告知').css("color", '#FFFF00') } }); $("[data-field='type']").children().each(function () { if ($(this).text() == 'DCD') { $(this).text('网络安全监测装置') } else if ($(this).text() == 'DB') { $(this).text('数据库') } else if ($(this).text() == 'IDS') { $(this).text('入侵检测系统') } else if ($(this).text() == 'AV') { $(this).text('防病毒系统') } else if ($(this).text() == 'VEAD') { $(this).text('纵向加密装置') } else if ($(this).text() == 'SW') { $(this).text('交换机') } else if ($(this).text() == 'SVR') { $(this).text('服务器') } else if ($(this).text() == 'BID') { $(this).text('横向方向隔离装置') } else if ($(this).text() == 'FID') { $(this).text('横向正向隔离装置') } else if ($(this).text() == 'FW') { $(this).text('防火墙') } }); } // done: function(res, curr, count){ // $("[data-field='pname']").children().each(function(){ // if($(this).text()==''){ // $(this).text("根目录"); // }else { // $(this).text($(this).text()); // } // }); // pageCurr=curr; // // } }); }) }) }
HTML部分
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> <head th:include="layout :: htmlhead" th:with="title='用户管理'"></head> <body class="layui-layout-body"> <div class="layui-layout layui-layout-admin"> <!--头--> <div th:replace="fragments/head :: header"></div> <div class="layui-body" style="margin: 1%"> <form id="userSearch" class="layui-form layui-form-pane" method="post" action="" style="margin-top: 20px;"> <div class="layui-font-20">选择设备资产 <button type="button" class="layui-btn layui-btn-sm" onclick="replaceDoc()" style="float: right">刷新</button></div> <table id="getMonitor" lay-filter="userTable" style="height: 20px" ></table> </form> <select name="city" lay-verify=""> <option value="">网络连接白名单</option> <option value="010">服务端口白名单</option> <option value="021">关键文件/目录清单</option> <option value="0571">存在光驱设备检测周期</option> <option value="0571">非法端口检测周期</option> <option value="0571">危险操作命令清单</option> </select> <table id="whitel" lay-filter="userTable" ></table> </div> <!--底部--> <div th:replace="fragments/footer :: footer"></div> <!-- <script src="/js/dateUtils.js"></script>--> <script src="/js/getMonitor.js"></script> <script src="/js/whitelist.js"></script> </div> </body> </html>
-
怎么通过mysql视图联查多个表的相同字段信息
2021-06-29 14:30:47怎么通过mysql视图联查多个表的相同字段信息 使用union 关键字 CERATE VIEW `user` AS SELECT `Username`,`Password` FROM `i_doctor` UNION SELECT `Username`,`Password` FROM `i_hospital` //查看视图 SELECT ... -
如何查询mysql两个表联查后有相同字段的更新另外字段值
2022-03-29 11:59:59问题遇到的现象和发生背景 现有2个表,分别为: data_1014(data_id,fd64) data_1018(data_n_id,data_id,fd70) 说明: 1、data_1018中的data_id等于data_1014中的data_id 2、data_1014中的data_id是唯一的,不... -
MyBatis 多表关联相同字段的解决方案,springmvc面试题高级
2021-08-28 17:56:59然后在下面的`select`语句中查询时再给字段起个相同的别名: 最后 针对以上面试题,小编已经把面试题+答案整理好了,想要获取这份面试题+答案的朋友帮忙点赞后,戳这里免费领取就可以了 面试专题 除了以上面试题+...private Integer id; private String name; private Integer age; private String address; //一对多映射集合 private List<Account> accounts;
}
实体类2:Account.java
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Account {
private Integer id; private Integer uid; private Double money;
}
UserMapper 接口:
public interface UserMapper {
List<User> findAllUser();
}
mapper.xml文件:下面写法是错误的,这样查出来的`id`只有一个
<resultMap id="userAccountMap" type="user"> <id column="id" property="id"/> <result column="name" property="name"/> <result column="age" property="age"/> <result column="address" property="address"/> <collection property="accounts" javaType="ArrayList" ofType="Account"> <id column="id" property="id"/> <result column="uid" property="uid"/> <result column="money" property="money"/> </collection> </resultMap> <select id="findAllUser" resultMap="userAccountMap"> select u.id, u.name, u.age, u.address, a.id, a.uid, a.money from user u left join account a on u.id = a.uid; </select>
[](https://codechina.csdn.net/m0_60958482/java-p7)解决方案 ======================================================================= 要解决这个问题很简单,拿上面的例子来说,我们要给结果集`userAccountMap`的字段起个别名,然后在下面的`select`语句中查询时再给字段起个相同的别名:
<resultMap id="userAccountMap" type="user"> <id column="id1" property="id"/> <!--此处给父表的id起了别名id1--> <result column="name" property="name"/> <result column="age" property="age"/> <result column="address" property="address"/> <collection property="accounts" javaType="ArrayList" ofType="Account"> <id column="id" property="id"/> <!--此处给子表的id起了别名id2-->
最后
针对以上面试题,小编已经把面试题+答案整理好了,想要获取这份面试题+答案的朋友帮忙点赞后,戳这里免费领取就可以了
面试专题
除了以上面试题+答案,小编同时还整理了微服务相关的实战文档也可以分享给大家学习
-mYMM7Br1-1630144608838)]
除了以上面试题+答案,小编同时还整理了微服务相关的实战文档也可以分享给大家学习
[外链图片转存中…(img-nma7bMxC-1630144608840)]
[外链图片转存中…(img-Uinq8BgK-1630144608841)]
-
mybatis多表联查重复字段问题及解决
2020-02-21 19:56:23为了使两表联合查询时两个img_addr能区分开,在resultMap中给第二个表的img_Addr起一个别名,并写入column属性中。 具体查询语句为: 如此,就能防止查询过程中第二个表的img_Addr的字段与第一个表的img_... -
mysql两个字段相同的表联合查询(union的使用)
2021-01-19 03:22:31mysql两个字段相同的表联合查询(union的使用)在维护使用的多个表的时候遇到了需要跨表统计信息的需求,经查询可以使用union和union all语句实现union和union all都是组合多个表的内容然后作为一个表输出。... -
多表联合查询字段相同的映射
2021-09-25 13:49:30当有多个表进行联合查询时,[inner join 和join等价:这个可以去除某个表数据行与之对应的数据行全为null时] 多个表的表字段名称相同时,在进行查询时,可以使用别名的方式进行区分。其映射问题,应将 <result... -
MyBatis多表联查,两个表中字段名称重复,重复字段映射造成数据错误
2019-04-25 16:56:49MyBatis 使用多表联查,两张表中字段重复时,采用取别名方法解决 结果显示图: product.* 里面包含了name属性,category也有name属性,所以将category.name 取了别名"category_name" 映射 : <resultMap id=... -
SQL 将两张包含相同字段和不同字段的表数据合并成一张表
2022-01-26 17:12:07此为SQL案例:将两张具备相同字段,有一部分字段不相同的两张表获取查询结果为整合之后的。 两张表 table1 table2 我想要将两者的数据进行合并达到如下的效果: 这里限制条件有两个分别是date,code 两个,只有当... -
Mysql3个字段,任何一个字段的值相同则为重复,语句应该怎么写?
2021-01-26 06:27:20我试了这个语句:SELECT DISTINCT a,b,c FROM `table`结果不对,查出来的是3个字段都相同才排除而我要的是3个字段中任意一个字段的值相同就排除等于说实现的效果跟把这3个字段设置成唯一键值一样的导量,查询这... -
MySQL 查询多张表中类型相同字段的最大值
2021-08-04 06:06:25表结构 实现一:利用MySQL函数:GREATEST(value1,value2,...) SELECT GREATEST( (SELECT max(price) from tb_goods), (SELECT max(price) from tb_goods2) ) 实现二:利用存储过程 -- 使用存储过程 ... -
oracle根据相同字段拼接另外不同字段数据,用逗号隔开。
2021-03-16 16:40:19table为表名,id为相同字段,name为不同字段 select id, ltrim(sys_connect_by_path(name, ','), ',') name from (select id, name, row_number() over(partition by id order by name) rn, count(*) over(partition... -
MySql两表联查字段被覆盖
2020-04-22 21:24:17今天做一个项目时写sql语句遇到字段被覆盖,请教了大佬后,特意记录一下,因为的sql编写能力是真的弱,问题如下:mysql两张表,一个是机场信息表,一个是航班信息表中有起飞机场id,降落机场id,要查询航班信息中起... -
两表联查是关联字段的值位数不一样时怎么办???
2016-10-10 16:11:00LPAD(str,len,padstr) 返回字符串str,左填充用字符串padstr填补到len字符长度。 如果str为大于len长,返回值被缩短至len个字符(即,不能超过 len 长)。 select DISTINCT(b.name) from a, b where LPAD(b.bid,... -
MyBatis两张表中存在相同字段名,联表查询时的冲突解决办法
2017-11-20 12:44:461. 经常使用类似left join做查询,偶尔遇到两张表的字段名相同(即column名字一致),此时可以在mybatis中这样配置 例子: SELECT DISTINCT t1.username, t1.password, t2.username "t2_username", -
sql语句多表连接查询,根据其中两个字段相同的去重
2022-01-04 14:38:40ID(组织ID) 例如:2123这个人员ID对应了77和82两个组织ID 做三表关联,希望达到只显示一行2123这个人员ID的数据,根据EMPLOYEE_ID字段去重 一个人员ID对应多个组织ID的时候,只显示一条数据,根据人员ID去重。... -
thinkphp多表查询两表有重复相同字段解决方法
2016-07-15 11:11:56框架:thinkphp 版本:3.2.3 内容:查询语句 解决问题:重复字段问题 $Data = M('a')->where($where) ->Field('a.name as aname,b.name as uname,a.*') ->join('b o -
同一张表有两个字段联查字典表
2019-09-19 14:31:50在我们的查询中部门表在连接的右边,如果我们想知道右边表中的所有记录信息,那么就可以采用右外连接,如果此记录在左边的表中找不到匹配项,则相应字段(employeeid,employeename)为NULL 检索语句为: SELECT e... -
两张表相同字段同列输出(union/unionAll)
2018-12-13 13:44:21事先阅读 ... 表1: CREATE TABLE `A` ( `id` int(11) NOT NULL AUTO_INCREMENT, `orderno` bigint(20) DEFAULT NULL , `userid` varchar(255) DEFAULT NULL, `resul... -
MySQL根据相同字段内容两表关联赋值
2020-08-10 15:29:18要通过A,B中均有的社区字段进行匹配,将B中的社区代码code赋值给A 下面是MySQL 语句代码。 //mysql> UPDATE A,B(表名A,B) SET A.A1=B.B1 WHERE A.A2=B.B2; mysql> update address,community set address.... -
【MySQL 查询 将Id相同的记录的字段合并,并且以逗号分隔】
2022-03-01 16:34:23需要将字段查询结果合并,如下:  sql 如下 : SELECT Id,GROUP_CONCAT(`Name` SEPARATOR ',') NAMES FROM `stu` ... -
laravel 查询构造器 两表联查 A表多个字段关联一个B表一个字段
2021-04-25 11:37:19$data = DB::table('draft_sound as a') ->select('a.dialect_name','b.name as province_name','c.name as city_name','d.name as district_name','a.file_name') ->join('china_area as b','a.province_id... -
多表联查 若某一字段相同 且有状态跟时间字段,选取该状态下 时间最近的一条数据
2015-10-16 17:00:16select info.* from ( select ws.pk, ra.pk poaId, rb.resource_name, rb.resource_type, to_char(ra.calendar_start -
多表联查比较 两张表相同字段的avg
2017-09-19 15:53:36想通过比较同一张表中不同ID的avg(value)大小来获取平均值较大的count(id) -
laravel查询表中字段值相同的所有数据
2020-08-29 16:56:30laravel查询表中字段值相同的所有数据 例:我要查询partner表中,cellphone字段里值,所有相同的所有数据 $phone = Partner::select('cellphone', DB::raw('COUNT(*) as count')) ->groupBy('cellphone') ->... -
Mybatis中多表联查,查询出来的字段出现重名,造成数据异常的解决方法!
2018-08-08 18:11:36在做一对多出现的问题,引发的思考:当数据库表中,主表的主键id和明细表的中的字段名相同时怎么办?Mybatis进行自动映射赋值的时候会不会出现异常? 注意:Mybatis中做多表联查的时候,不管是一对一、一对多、一...