文档章节

Spring+SpringMVC+Mybatis+EasyUI古诗搜索系统(四---java代码)

northsailor
 northsailor
发布于 2016/07/14 17:34
字数 988
阅读 9
收藏 0

Poetries.java

package com.jikexueyuan.entity;

import java.io.Serializable;

/**
 * 诗句模型
 * 
 * @author 黄建清
 *
 */
public class Poetries implements Serializable {
	private static final long serialVersionUID = -4657536584850251820L;
	private Integer id;
	private Poets poets;
	private String content;
	private String title;

	public Poetries() {
	}

	public Poetries(Integer id, Poets poets, String content, String title) {
		super();
		this.id = id;
		this.poets = poets;
		this.content = content;
		this.title = title;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Poets getPoets() {
		return poets;
	}

	public void setPoets(Poets poets) {
		this.poets = poets;
	}

}

Poets.java

package com.jikexueyuan.entity;

import java.io.Serializable;
/**
 * 诗人模型bean
 */
import java.util.List;

public class Poets implements Serializable {
	private static final long serialVersionUID = 2255213471279022629L;
	private Integer id;
	private String name;
	private List<Poetries> poetries;

	public Poets() {
	}

	public Poets(String name) {
		super();
		this.name = name;
	}

	public Poets(Integer id, String name, List<Poetries> poetries) {
		super();
		this.id = id;
		this.name = name;
		this.poetries = poetries;
	}

	public Poets(Integer id) {
		super();
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Poetries> getPoetries() {
		return poetries;
	}

	public void setPoetries(List<Poetries> poetries) {
		this.poetries = poetries;
	}

}

用来分装分页信息的model,pageModel.java

package com.jikexueyuan.entity;

import java.util.List;
/**
 * 页面模型bean
 * @author Administrator
 *
 * @param <T>
 */
public class PageModel<T> {
	private Integer pageNumber; // 当前页数
	private Integer pageSize; // 一页显示数量
	@SuppressWarnings("unused")
	private Integer startRow; // 查询起始行
	private Integer total; // 总记录行数
	@SuppressWarnings("rawtypes")
	private List rows; // 查询结果数据
	private T queryObj; // 查询对象
	
	public PageModel() {
		super();
	}
	
	

	public PageModel(T queryObj) {
		super();
		this.queryObj = queryObj;
	}
	


	public PageModel(Integer pageNumber, Integer pageSize, T queryObj) {
		super();
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.queryObj = queryObj;
	}



	public PageModel(Integer pageNumber, Integer pageSize, Integer startRow,
			Integer total, @SuppressWarnings("rawtypes") List rows, T queryObj) {
		super();
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.startRow = startRow;
		this.total = total;
		this.rows = rows;
		this.queryObj = queryObj;
	}



	public PageModel(Integer pageSize, Integer startRow) {
		super();
		this.pageSize = pageSize;
		this.startRow = startRow;
	}
	
	@SuppressWarnings("rawtypes")
	public List getRows() {
		return rows;
	}



	@SuppressWarnings("rawtypes")
	public void setRows(List rows) {
		this.rows = rows;
	}



	public Integer getStartRow() {
		if (pageNumber != null && pageSize != null) {
			return (pageNumber - 1) * pageSize;
		} else {
			return 0;
		}
	}

	public Integer getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}


	public void setQueryObj(T queryObj) {
		this.queryObj = queryObj;
	}

	public T getQueryObj() {
		return queryObj;
	}
}

mapper文件

PoetriesMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 关联查询 -->
<mapper namespace="com.jikexueyuan.dao.PoetriesDao">
	<sql id="sql_count">
		SELECT COUNT(*)
	</sql>
	<sql id="sql_select">
		SELECT poetries.*,poets.*
	</sql>
	<sql id="sql_where">
		FROM poets INNER JOIN poetries ON poets.id=poetries.poet_id
		<where>
			<if test="queryObj != null">
				<!-- 如果选择输入名句,则按照名句搜索诗词 -->
				<if test="queryObj.content != null and  queryObj.content != ''">
					AND content like CONCAT ('%',#{queryObj.content},'%')
				</if>
				<!-- 如果选择输入题目,则按照题目搜索诗词 -->
				<if test="queryObj.title != null">
					AND title = #{queryObj.title}
				</if>
			</if>
		</where>
	</sql>
	<select id="selectPoeListWithPage" parameterType="com.jikexueyuan.entity.PageModel"
		resultMap="poetyMap">
		<include refid="sql_select"></include>
		<include refid="sql_where"></include>
		<!-- 分页 -->
		<if test="pageNumber != null and  pageSize!= null">
			limit #{startRow},#{pageSize}
		</if>
	</select>
	<select id="selectPoeCountWithPage" parameterType="com.jikexueyuan.entity.PageModel"
		resultType="java.lang.Integer">
		<include refid="sql_count"></include>
		<include refid="sql_where"></include>
	</select>
	<resultMap type="Map" id="poetyMap">
		<id column="id" property="poetries.id" />
		<result column="title" property="title" />
		<result column="content" property="content" />
		<association property="poets" column="poet_id"
			javaType="com.jikexueyuan.entity.Poets">
			<id property="id" column="poets.id" />
			<result property="name" column="name" />
		</association>
	</resultMap>
</mapper> 

PoetsMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jikexueyuan.dao.PoetsDao">
	<!-- 嵌套查询 ,通过诗人名搜索标题与内容 -->
	<sql id="sql_count">
		SELECT COUNT(*)
	</sql>
	<sql id="sql_select">
		SELECT poetries.*,poets.*
	</sql>
	<sql id="sql_where">
		FROM poets INNER JOIN poetries ON poets.id=poetries.poet_id
		<where>
			<if test="queryObj != null">
				<!-- 如果输入诗人,则按照诗人搜索诗词 -->
				<if test="queryObj.name != null">
					AND name = #{queryObj.name}
				</if>
			</if>
		</where>
	</sql>
	<select id="findByName" parameterType="com.jikexueyuan.entity.PageModel"
		resultMap="poetMap">
		<include refid="sql_select"></include>
		<include refid="sql_where"></include>
		<!-- 分页 -->
		<if test="pageNumber != null and  pageSize!= null">
			limit #{startRow},#{pageSize}
		</if>
	</select>
	<resultMap type="Map" id="poetMap">
		<id column="id" property="poetries.id" />
		<result column="title" property="title" />
		<result column="content" property="content" />
	</resultMap>
	<select id="countWithPage" parameterType="com.jikexueyuan.entity.PageModel"
		resultType="java.lang.Integer">
		<include refid="sql_count"></include>
		<include refid="sql_where"></include>
	</select>
</mapper> 

dao层

PoetriesDao.java

package com.jikexueyuan.dao;

import java.util.List;
import java.util.Map;

import com.jikexueyuan.annotation.MyBatisRepository;
import com.jikexueyuan.entity.PageModel;
import com.jikexueyuan.entity.Poetries;
/**
 * 诗词表的DAO组件
 */
@MyBatisRepository
public interface PoetriesDao {
	@SuppressWarnings("rawtypes")
	public List<Map> selectPoeListWithPage(PageModel<Poetries> pageModel);
	public Integer selectPoeCountWithPage(PageModel<Poetries> pageModel);

}

Poets.java

package com.jikexueyuan.dao;

import java.util.List;
import java.util.Map;

import com.jikexueyuan.annotation.MyBatisRepository;
import com.jikexueyuan.entity.PageModel;
import com.jikexueyuan.entity.Poets;
/**
 * 诗词表的DAO组件
 */
@MyBatisRepository
public interface PoetsDao {
	@SuppressWarnings("rawtypes")
	public List<Map> findByName(PageModel<Poets> pageModel);
	public Integer countWithPage(PageModel<Poets> pageModel);
}

service层

PoetriesServiceImpl.java

package com.jikexueyuan.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jikexueyuan.dao.PoetriesDao;
import com.jikexueyuan.entity.PageModel;
import com.jikexueyuan.entity.Poetries;
import com.jikexueyuan.service.PoetriesService;
@Service
public class PoetriesServiceImpl implements PoetriesService {
	@Resource
	private PoetriesDao poetriesDao;

	@Override
	public void listPoeWithPage(PageModel<Poetries> pageModel){
		/*把诗句集合设置给rows*/
		pageModel.setRows(poetriesDao.selectPoeListWithPage(pageModel));
		/*把总数设置给total*/
		pageModel.setTotal(poetriesDao.selectPoeCountWithPage(pageModel));
	}
}

PoetsServiceImpl.java

package com.jikexueyuan.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jikexueyuan.dao.PoetsDao;
import com.jikexueyuan.entity.PageModel;
import com.jikexueyuan.entity.Poets;
import com.jikexueyuan.service.PoetsService;
@Service
public class PoetsServiceImpl implements PoetsService {
	@Resource
	private PoetsDao poetsDao;
	@Override
	public void listByName(PageModel<Poets> pageModel) {
		pageModel.setRows(poetsDao.findByName(pageModel));
		pageModel.setTotal(poetsDao.countWithPage(pageModel));
	}

}

 

© 著作权归作者所有

共有 人打赏支持
northsailor
粉丝 1
博文 5
码字总数 3598
作品 0
兰州
程序员
私信 提问
基于java五子棋游戏开发(含源文件)

获取项目源文件,联系Q:1225467431,指导其它毕设,课设 摘要:五子棋作为中国古代的传统黑白棋种之一,有着广泛的群众基础,是一种老少皆宜的棋类休闲游戏。开发一款五子棋游戏可以使广大棋牌...

切梦刀
01/04
0
0
JAVA坏境变量中的JAVA_HOME path classpath 的设置与作用

一、安装JDK 选择安装目录 安装过程中会出现两次 安装提示 。第一次是安装 jdk ,第二次是安装 jre 。建议两个都安装在同一个java文件夹中的不同文件夹中。(不能都安装在java文件夹的根目录...

Java编程思想
2013/06/26
0
0
win10系统JDK8安装环境配置教程

本节博主主要介绍jdk8的安装,以及一些注意事项,同时博主也需要留着配置路径自己以后使用。 安装步骤: (一)下载JDK官网地址:http://www.oracle.com/technetwork/java/javase/downloads...

em_aaron
2018/08/04
0
0
结合JVM源码谈Java类加载器

一、前言 之前文章 Java 类加载器揭秘 从Java层面讲解了Java类加载器的原理,这里我们结合JVM源码在稍微深入讲解下。 二、Java类加载器的委托机制 Java 类加载器使用的是委托机制,也就是一个...

阿里加多
2018/04/29
0
0
Java中系统属性Properties介绍 System.getProperty()参数大全

在JDK文档中System类中有这样的方法getProperties()在此方法的详细介绍中有下面的参数可供使用: java.version Java 运行时环境版本 java.vendor Java 运行时环境供应商 java.vendor.url Ja...

星痕2018
2012/05/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

TiDB 源码阅读系列文章(二十四)TiDB Binlog 源码解析

作者:姚维 TiDB Binlog Overview 这篇文章不是讲 TiDB Binlog 组件的源码,而是讲 TiDB 在执行 DML/DDL 语句过程中,如何将 Binlog 数据 发送给 TiDB Binlog 集群的 Pump 组件。目前 TiDB 在...

TiDB
18分钟前
0
0
Oracle第三方工具PLSQL注册码

注册码: Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqz serial Number:601769 password:xs374ca 这个注册码是PLSQL 11版本通用的,刚刚在官网下载了最新版11.0.6版,用 此激活码成功...

小橙子的曼曼
20分钟前
0
0
深度学习为图片人物换装【python代码教程】

在观看本文之前,请答应我要善良。昨天预告了下,发现很多同学对这个模型都表示出兴趣,甚至有好多同学后台发来照片让我帮他们脱裤子。授人以鱼不如授人以渔,请这些同学好自为之~ 01效果演示...

阿里云官方博客
39分钟前
5
0
centos7安装RabbitMQ详细过程

由于RabbitMQ是基于Erlang语言开发,所以在安装RabbitMQ之前,需要先安装Erlang 1、环境: centos 7.1 内核版本3.10.0-229.el7.x86_64 Erlang 19.0.4版本 RabbitMQ 3.6.14版本 2、在线安装E...

秋至丶枫以落
今天
1
0
6个使用KeePassX保护密码的技巧

虽然安全是个深奥的主题,但是你可以遵循几个简单的日常习惯来减小攻击面。本文将解释确保密码信息安全的重要性,并给出如何充分利用KeePassX的建议。 日益互联的数字世界使安全成为一个重要...

Linux就该这么学
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部