项目使用springmvc后,在后台的文件结构如下:
- com
service
controller
dao
model - resources
conf- apache-shiro.xml
- applicationContext.xml
- ehcache.xml
- ehcache-shiro.xml
- jdbc.properties
- log4j.properties
- mybatis-config.xml
- spring.xml
- spring-mvc.xml
- spring-mybatis.xml
sqlMapper
- ActivityMapper.xml
- ContentMapper.xml
- CusBuyProMapper.xml
- MenuMapper.xml
- NavMapper.xml
在controller文件夹下的文件内容一般如下
package xxx;
import xxx;
@controller
@RequestMapping("/dfdsf")
public class ActivityCtrl{
@Autowired
private ActivityService as ;
@RequestMappine(value="/sdfd" , method=RequestMethod.POST)
public String sdfd(@RequestBody User user) throws Exception{
return "success";
}
}
在DAO文件夹下
package hpe.com.dao;
import hpe.com.model.PageBean;
import hpe.com.model.Activity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ActivityDAO {
List<Activity> getActivityList() throws Exception;
List<Activity> findActivityByPage(@Param("pb")PageBean pb, @Param("act")Activity act) throws Exception;
int ActivityPageCount(Activity act) throws Exception;
Activity selectByActivityId(Integer id) throws Exception;
boolean updateByActivityId(Activity act) throws Exception;
boolean addActivity(Activity act)throws Exception;
boolean delActivity(Integer id) throws Exception;
}
在model文件夹下
package hpe.com.model;
/**
* Created by zhazhiho on 2017-04-25.
*/
public class Activity {
private int id;
private String acName;
private String acContent;
private String acHref;
private String acImg;
private String acContPage;
public String getAcContPage() {
return acContPage;
}
public void setAcContPage(String acContPage) {
this.acContPage = acContPage;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAcName() {
return acName;
}
public void setAcName(String acName) {
this.acName = acName;
}
public String getAcContent() {
return acContent;
}
public void setAcContent(String acContent) {
this.acContent = acContent;
}
public String getAcHref() {
return acHref;
}
public void setAcHref(String acHref) {
this.acHref = acHref;
}
public String getAcImg() {
return acImg;
}
public void setAcImg(String acImg) {
this.acImg = acImg;
}
}
在service文件夹下
package hpe.com.service;
import hpe.com.model.Activity;
import hpe.com.model.PageBean;
import java.util.List;
public interface ActivityService {
List<Activity> getActivityList() throws Exception;
List<Activity> findActivityByPage(PageBean pb, Activity act) throws Exception;
int ActivityPageCount(Activity act) throws Exception;
Activity selectByActivityId(Integer id) throws Exception;
boolean updateByActivityId(Activity act) throws Exception;
boolean addActivity(Activity act)throws Exception;
boolean delActivity(Integer id) throws Exception;
}
package hpe.com.service.impl;
import hpe.com.dao.ActivityDAO;
import hpe.com.model.Activity;
import hpe.com.model.PageBean;
import hpe.com.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ActivityServiceImpl implements ActivityService{
@Autowired
private ActivityDAO ad;
@Override
public List<Activity> getActivityList() throws Exception {
return ad.getActivityList();
}
@Override
public List<Activity> findActivityByPage(PageBean pb, Activity act) throws Exception {
return ad.findActivityByPage(pb,act);
}
@Override
public int ActivityPageCount(Activity act) throws Exception {
return ad.ActivityPageCount(act);
}
@Override
public Activity selectByActivityId(Integer id) throws Exception {
return ad.selectByActivityId(id);
}
@Override
public boolean updateByActivityId(Activity act) throws Exception {
return ad.updateByActivityId(act);
}
@Override
public boolean addActivity(Activity act) throws Exception {
return ad.addActivity(act);
}
@Override
public boolean delActivity(Integer id) throws Exception {
return ad.delActivity(id);
}
}
在sqlMapper.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="hpe.com.dao.ActivityDAO">
<resultMap id="BaseResultMap" type="Activity">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="acName" property="acName" jdbcType="VARCHAR" />
<result column="acContent" property="acContent" jdbcType="VARCHAR" />
<result column="acHref" property="acHref" jdbcType="VARCHAR" />
<result column="acImg" property="acImg" jdbcType="VARCHAR" />
<result column="acContPage" property="acContPage" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
id,acName,acContent,acHref,acImg,acContPage
</sql>
<select id="getActivityList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
From activity
</select>
<select id="findActivityByPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from (select * from activity
<where>
<if test="act.id!=null and act.id!='' ">
and id LIKE CONCAT('%', #{act.id},'%')
</if>
<if test="act.acName!=null and act.acName!='' ">
and acName LIKE CONCAT('%', #{act.acName},'%')
</if>
</where>) activity
limit #{pb.start} , #{pb.size}
</select>
<select id="ActivityPageCount" resultType="int" parameterType="Activity">
select count(*) from (select * from activity
<where>
<if test="id!=null and id!='' ">
and id LIKE CONCAT('%', #{id},'%')
</if>
<if test="acName!=null and acName!='' ">
and acName LIKE CONCAT('%', #{acName},'%')
</if>
</where>) activity
</select>
<select id="selectByActivityId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select * from activity where id = #{id}
</select>
<update id="updateByActivityId" parameterType="hpe.com.model.Activity">
update activity
set
acName = #{acName,jdbcType=VARCHAR},
acContent = #{acContent,jdbcType=VARCHAR},
acHref = #{acHref,jdbcType=VARCHAR},
acImg = #{acImg,jdbcType=VARCHAR},
acContPage = #{acContPage,jdbcType=VARCHAR}
where id=#{id}
</update>
<insert id="addActivity" parameterType="hpe.com.model.Activity" keyProperty="id">
insert
into activity(acName,acContent,acHref,acImg,acContPage)
values
(
#{acName},#{acContent},#{acHref},#{acImg},#{acContPage})
</insert>
<delete id="delActivity" parameterType="Integer">
delete from activity where id=#{id}
</delete>
</mapper>
网友评论