SQL查询
							parent
							
								
									710a83d962
								
							
						
					
					
						commit
						7a658ce8b2
					
				| 
						 | 
				
			
			@ -44,33 +44,24 @@ public class DcxServiceImpl implements DcxService {
 | 
			
		|||
        int pageSize = query.getPageSize();//条数
 | 
			
		||||
        System.out.println("当前页:" + pageNum);
 | 
			
		||||
        System.out.println("条数:" + pageSize);
 | 
			
		||||
        String sql = "from (SELECT ROW_NUMBER() OVER(ORDER BY it.id) AS RowNum, it.id ,"
 | 
			
		||||
        String sql = " from (SELECT ROW_NUMBER() OVER(ORDER BY it.id) AS RowNum, it.id ,"
 | 
			
		||||
                + "it.code,"
 | 
			
		||||
                + "it.name"
 | 
			
		||||
                + " from Item it ";
 | 
			
		||||
        sql += ")  AS subquery ";
 | 
			
		||||
        String sqlCount = "select count(id) " + sql;
 | 
			
		||||
        String sqlCount = "select count(id) as nums " + sql;
 | 
			
		||||
        sql = "select * " + sql + " WHERE RowNum BETWEEN " + (pageNum-1) * pageSize + " AND " + (pageNum) * pageSize;
 | 
			
		||||
        log.info("sqlCount:"+sqlCount);
 | 
			
		||||
        log.info("sql:"+sql);
 | 
			
		||||
 | 
			
		||||
        //查询单挑数据
 | 
			
		||||
        Map<String,Object> userMap2 = jdbcTemplate.queryForMap("select * from Container where ID=1", new HashMap<>());
 | 
			
		||||
 | 
			
		||||
        //查询单数据
 | 
			
		||||
        Map<String,Object> listCount = jdbcTemplate.queryForMap(sqlCount, new HashMap<>());
 | 
			
		||||
        //查询多条数据据
 | 
			
		||||
        List<Map<String,Object>> userMap = jdbcTemplate.queryForList("select * from Container ", new HashMap<>());
 | 
			
		||||
        System.out.println(userMap);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /*List<Object[]> list=entity.createNativeQuery(sql).getResultList();
 | 
			
		||||
        List listCount=entity.createNativeQuery(sqlCount).getResultList();
 | 
			
		||||
        List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql, new HashMap<>());
 | 
			
		||||
        JSONArray data = new JSONArray();
 | 
			
		||||
        for(Object[] obj:list){
 | 
			
		||||
        for(Map<String,Object> m:maps){
 | 
			
		||||
            int i=0;
 | 
			
		||||
            JSONObject d = new JSONObject();
 | 
			
		||||
            d.put("id",obj[i++]==null?"":obj[i-1]);
 | 
			
		||||
            d.put("userNo",obj[i++]==null?"":obj[i-1]);
 | 
			
		||||
            d.put("userName", obj[i++]==null?"":obj[i-1]);
 | 
			
		||||
            d.put("id",m.get("id"));
 | 
			
		||||
            d.put("userNo",m.get("code"));
 | 
			
		||||
            d.put("userName", m.get("name"));
 | 
			
		||||
            d.put("passWord","123456");
 | 
			
		||||
            d.put("age",19);
 | 
			
		||||
            d.put("sex",1);
 | 
			
		||||
| 
						 | 
				
			
			@ -78,8 +69,8 @@ public class DcxServiceImpl implements DcxService {
 | 
			
		|||
            d.put("roleId", 2);
 | 
			
		||||
            d.put("isValid", false);
 | 
			
		||||
            data.add(d);
 | 
			
		||||
        }*/
 | 
			
		||||
       return  Result.success(userMap.size(),userMap);
 | 
			
		||||
        }
 | 
			
		||||
       return  Result.success(Long.parseLong(listCount.get("nums").toString()),data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,25 +0,0 @@
 | 
			
		|||
package com.yc.wms.until;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.annotation.DbType;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 | 
			
		||||
import org.mybatis.spring.annotation.MapperScan;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
 | 
			
		||||
@Configuration
 | 
			
		||||
@MapperScan("com.yc.wms.mapper")
 | 
			
		||||
public class MybatisPlusConfig {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
 | 
			
		||||
     */
 | 
			
		||||
    @Bean
 | 
			
		||||
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
 | 
			
		||||
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
 | 
			
		||||
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
 | 
			
		||||
        return interceptor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue