网上大多例子是 mySql,今天捣鼓了一个上午,终于写了访问 Oracle的实例,欣喜之余,分享一下下:
1、POM文件
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/ojdbc6-11.2.0.3.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.2</version>
</dependency>
2、UserMapper.xml
<select id="getAllUserList" parameterType="String" resultMap="UserMapper">
select id,login_name,user_name,user_password from sys_user
<where>
<if test="loginName!=null and loginName!='' ">
and login_name like #{loginName}
</if>
</where>
</select>
3、Controller
@RequestMapping("/userList")
@ResponseBody
public Map getAllUserList(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize, String loginName) throws Exception {
PageHelper.startPage(pageNo,pageSize);
List<User> userList = userService.getAllUserList(loginName);
PageInfo<User> pageInfo = new PageInfo<User>(userList);
Map map = new HashMap();
map.put("page", pageInfo);
map.put("totalPage", 5);
return map;
}
4、前端页面
var getUserList = function (curr) {
$.ajax({
type: 'POST',
url: '../user/userList',
dataType: 'json',
data: {
pageSize: 10,
pageNo: curr || 1,
loginName: $("#loginName").val()
},
success: function (msg) {
app.result = msg.page.list;
laypage({
cont: 'pagenav', //分页容器
pages: msg.totalPage, //总页数
skin: '#333333',
first: '第一页',
last: '最后一页',
curr: curr || 1,
jump: function (obj, first) {
if (!first) {
getUserList(obj.curr);
}
}
});
}
});
}