Skip to content

Commit

Permalink
添加分页查询测试
Browse files Browse the repository at this point in the history
  • Loading branch information
fansy1990 committed Jul 29, 2016
1 parent 379243c commit c69923b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/main/java/demo/controller/NodeController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -26,6 +28,19 @@ public ModelAndView getNodeList(int id) {

}

@RequestMapping(value = "getData")
public ModelAndView getData(int start, int end) {
ModelAndView modelAndView = new ModelAndView();
List<Node> nodes = nodeService.getData(start, end);

System.out.println(nodes);
// println(node);
modelAndView.addObject("node", nodes);

return modelAndView;

}

public NodeService getNodeService() {
return nodeService;
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/demo/dao/NodeMapper.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package demo.dao;

import java.util.List;

import demo.model.Node;

public interface NodeMapper {
int deleteByPrimaryKey(Integer id);
int deleteByPrimaryKey(Integer id);

int insert(Node record);

int insert(Node record);
int insertSelective(Node record);

int insertSelective(Node record);
Node selectByPrimaryKey(Integer id);

Node selectByPrimaryKey(Integer id);
List<Node> selectPage(Integer start, Integer end);

int updateByPrimaryKeySelective(Node record);
int updateByPrimaryKeySelective(Node record);

int updateByPrimaryKey(Node record);
int updateByPrimaryKey(Node record);
}
12 changes: 12 additions & 0 deletions src/main/java/demo/model/NodeMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

<collection property="children" ofType="demo.model.Node" column="id" select="getChildrenList"/>
</resultMap>
<resultMap type="demo.model.Node" id="NormalResultMap">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="folder" jdbcType="INTEGER" property="folder" />
<result column="pid" property="pid"/>
</resultMap>
<sql id="Base_Column_List">
id, name, folder,pid
</sql>
Expand All @@ -17,6 +23,12 @@
from table_node t
where t.id = #{id,jdbcType=INTEGER}
</select>

<select id="selectPage" resultMap="NormalResultMap">

select t.* from table_node t where t.id between #{param1} and #{param2}
</select>

<select id="getChildrenList" resultMap="BaseResultMap">
select t.* from table_node t where t.pid= #{id,jdbcType=INTEGER}
</select>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/demo/service/NodeService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -16,6 +18,10 @@ public Node getNodes(int id) {
return this.nodeMapper.selectByPrimaryKey(id);
}

public List<Node> getData(int start, int end) {
return this.nodeMapper.selectPage(start, end);
}

public NodeMapper getNodeMapper() {
return nodeMapper;
}
Expand Down

0 comments on commit c69923b

Please sign in to comment.