文档章节

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坏境变量中的JAVA_HOME path classpath 的设置与作用

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

Java编程思想
2013/06/26
0
0
在ubuntu上安装netbeans出问题:“无法初始化 UI 正在 headless 模式下运行"

综合了网上的资料,并进行实际操作,记录如下: 1.安装oracle java jdk(jdk-6u31-linux-i586),并已在profile文件中注明JAVA_HOME的路径。 2.由于ubuntu中可能会有默认的jdk,如openjdk。假...

银河星沙
2012/09/21
0
0
win10系统JDK8安装环境配置教程

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

em_aaron
08/04
0
0
java安全沙箱(四)之安全管理器及Java API

java是一种类型安全的语言,它有四类称为安全沙箱机制的安全机制来保证语言的安全性,这四类安全沙箱分别是: 类加载体系 .class文件检验器 内置于Java虚拟机(及语言)的安全特性 安全管理器...

xionghuiCoder
2015/09/04
0
0
linux配置java环境变量(详细)

一. 解压安装jdk 在shell终端下进入jdk-6u14-linux-i586.bin文件所在目录, 执行命令 ./jdk-6u14-linux-i586.bin 这时会出现一段协议,连继敲回车,当询问是否同意的时候,输入yes,回车。之...

冰玉翔龙
2013/03/28
0
0

没有更多内容

加载失败,请刷新页面

加载更多

图形用户界面和交互输入方法---图形数据的输入功能

图形数据的输入功能 输入模式 回显反馈

中国龙-扬科
6分钟前
0
0
互联网企业安全之端口监控

背景 外网端口监控系统是整个安全体系中非常重要的一环,它就像眼睛一样,时刻监控外网端口开放情况,并且在发现高危端口时能够及时提醒安全、运维人员做出相应处理。 对安全人员来说,互联网...

Skqing
9分钟前
0
0
JavaMonitor

常规监控jvm,都是比较麻烦的。但是今天在开源中国,看到了一个web版的javaMonitor。 虽然要在服务器上安装,但是这样的话,大家都能看见了。所以还是非常six的。 发现写了这个的博主也是非常...

miaojiangmin
13分钟前
0
0
Redis实践系列丨Codis数据迁移原理与优化

Codis介绍 Codis 是一种Redis集群的实现方案,与Redis社区的Redis cluster类似,基于slot的分片机制构建一个更大的Redis节点集群,对于连接到codis的Redis客户端来说, 除了部分不支持的命令外...

中间件小哥
13分钟前
0
0
HTTP常用状态码(14种)

类别 原因短语 1xx 信息型状态码 接收的请求正在处理 2xx 成功状态码 请求正常处理完毕 3xx 重定向状态码 需要进行附加操作以完成请求 4xx 客户端错误状态码 服务器无法处理请求 5xx 服务器错...

vio小黑
20分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部