Jeesite的七个文件:
Entity.java
EntityDao.java
EntityService.java
EntityController.java
EntityDao.xml
entityList.jsp
entityForm.jsp
七个文件的作用:
1. Entity.java:
定义使用到的属性名,以及set和get方法来对属性进行设置和获取
public class Entity extends DataEntity<Entity > {
private static final long serialVersionUID = 1L;//控制版本一致
private String major; // 专业
private String masterName; // 硕士名
//有参和无参构造器
public Entity () {
super();
}
public Entity (String id){
super(id);
}
//属性的get和set方法,可以由eclipse的source--Generate Getters and Setters自动生成
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getMasterName() {
return masterName;
}
public void setMasterName(String masterName) {
this.masterName = masterName;
}
}
2. EntityDao.java:
1. 接口,定义使用到的方法名,包括get/findList/findAllList/update/insert/…等方法名
2. 和EntityDao.xml连接,调用sql语句
public interface DistributeDao extends CrudDao<Distribute> {
//其父类定义有相关方法名
}
3. EntityService.java:
用来具体实现EntityDao.java中定义的方法
@Service
@Transactional(readOnly = true)//设置为只读
public class EntityService extends CrudService<EntityDao, Entity> {
public Entity get(String id) {
return super.get(id);
}
public List<Entity> findList(Entity entity) {
return super.findList(entity);
}
public Page<Entity> findPage(Page<Entity> page, Entity entity) {
return super.findPage(page, entity);
}
@Transactional(readOnly = false)
public void save(Entity entity) {
super.save(entity);
}
@Transactional(readOnly = false)
public void delete(Entity entity) {
super.delete(entity);
}
}
4. EntityController.java:
1. 定义了一些自定义方法,可以被jsp文件调用。
2. 该文件如果需要使用service的方法,可以创建service对象后调用所需要的方法
@Controller
@RequestMapping(value = "${adminPath}/gsmis/distribute")
//请求映射,value为该文件的地址。
public class DistributeController extends BaseController {
@Autowired//自动注入
private DistributeService distributeService;
@ModelAttribute//模型属性:无论调用什么方法都会优先执行该注解的方法
public Distribute get(@RequestParam(required=false) String id) {
Distribute entity = null;
if (StringUtils.isNotBlank(id)){
entity = distributeService.get(id);
}
if (entity == null){
entity = new Distribute();
}
return entity;
}//验证是否有值传过来
@RequiresPermissions("gsmis:distribute:view")//权限声明:view查看,edit编辑
@RequestMapping(value = {"list", ""})//jsp文件执行的方法名
public String list(Distribute distribute, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Distribute> page = distributeService.findPage(new Page<Distribute>(request, response), distribute); //考虑分页
model.addAttribute("page", page);//返回到jsp的值
return "imd/gsmis/distributeList";//返回jsp文件
}
@RequiresPermissions("gsmis:distribute:view")
@RequestMapping(value = "form")
public String form(Distribute distribute, Model model) {
model.addAttribute("distribute", distribute);
return "imd/gsmis/distributeForm";
}
5. EntityDao.xml:
调用数据库的·sql语句,负责对数据库的操作
<?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="cn.edu.ccnu.imd.gsmis.dao.DistributeDao">
<!--对多个属性批量操作-->
<sql id="distributeColumns">
a.id AS "id",
a.major AS "major",
a.masterName AS "masterName",
a.topic AS "topic",
a.studentID AS "studentID",
a.keywords AS "keywords",
a.status AS "status",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="distributeJoins">
</sql>
<select id="get" resultType="Distribute">
SELECT
<include refid="distributeColumns"/>
FROM thesis a
<include refid="distributeJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Distribute">
SELECT
<include refid="distributeColumns"/>
FROM thesis a
<include refid="distributeJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<!--模糊查询-->
<if test="major != null and major != ''">
AND a.major LIKE
<if test="dbName == 'oracle'">'%'||#{major}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{major}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{major},'%')</if>
</if>
<if test="masterName != null and masterName != ''">
AND a.masterName LIKE
<if test="dbName == 'oracle'">'%'||#{masterName}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{masterName}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{masterName},'%')</if>
</if>
<if test="studentID != null and studentID != ''">
AND a.studentID LIKE
<if test="dbName == 'oracle'">'%'||#{studentID}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{studentID}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{studentID},'%')</if>
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
</mapper>
6. entityList.jsp && entityForm.jsp:
jsp文件作为前台显示的页面,可以根据方法名对controller.java的方法进行调用
list:显示展示页面
form:显示提交页面
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>论文分配管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript">
$(document).ready(function() {
/* $("#distribute").click(function(){
<a href="${ctx}/gsmis/distribute/form?id=${distribute.id}">分配</a>
});*/
});
function page(n,s){
$("#pageNo").val(n);
$("#pageSize").val(s);
$("#searchForm").submit();
return false;
}
function selectall(){
if($('input[name="thesisId"]').get(0).checked){
$('input[name="thesisId"]').attr("checked",false);
}else{
$('input[name="thesisId"]').attr("checked",true);
/*$("input[name='documentId']").each(
function(){
if($(this).val() != "undefined"){
documentIds += $(this).val() + ","
}
}
) */
}
}
</script>
</head>
<body>
<ul class="nav nav-tabs">
<li class="active"><a href="${ctx}/gsmis/distribute/">论文分配列表</a></li>
</ul>
<form:form id="distributeForm" modelAttribute="distribute" action="${ctx}/gsmis/distribute/" method="post" class="breadcrumb form-search">
<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
<ul class="ul-form">
<li><label>专业:</label>
<form:input path="major" htmlEscape="false" maxlength="255" class="input-medium"/>
</li>
<li><label>姓名:</label>
<form:input path="masterName" htmlEscape="false" maxlength="255" class="input-medium"/>
</li>
<li><label>学号:</label>
<form:input path="studentID" htmlEscape="false" maxlength="255" class="input-medium"/>
</li>
<li class="btns">
<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
</li>
<li>
<a href = "${ctx}/gsmis/distribute/distribute"><input id="distribute" class="btn btn-primary" type="button" value="一键分配"/></a>
</li>
<li class="clearfix"></li>
</ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th style="text-align:center;"><a style="cursor:pointer;" onclick="selectall()">全选</a></th>
<th>专业</th>
<th>硕士名</th>
<th>论文主题</th>
<th>学号</th>
<th>关键字</th>
<th>分配状态</th>
<shiro:hasPermission name="gsmis:distribute:edit"><th>操作</th></shiro:hasPermission>
</tr>
</thead>
<tbody>
<c:forEach items="${page.list}" var="distribute">
<tr>
<td style="text-align:center;">
<input type="checkbox" name="thesisId" value="${thesis.id}"/>
</td>
<td>
${distribute.major}
</td>
<td>
${distribute.masterName}
</td>
<td>
${distribute.topic}
</td>
<td>
${distribute.studentID}
</td>
<td>
${distribute.keywords}
</td>
<td>
${distribute.status}
</td>
<shiro:hasPermission name="gsmis:distribute:edit">
<td>
<a href="${ctx}/gsmis/distribute/form?id=${distribute.id}">分配</a>
</td>
</shiro:hasPermission>
</tr>
</c:forEach>
</tbody>
</table>
<div class="pagination">${page}</div>
</body>
</html>