这是Controller包下的:
package com.hsaipin.controller;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hsaipin.model.Activity;
import com.hsaipin.model.DataModel;
import com.hsaipin.model.Pager;
import com.hsaipin.service.ActivityService;
@Controller
public class ActivityController {
@Resource(name="activityService")
private ActivityService activityService;
@RequestMapping("activityList")
public ModelAndView activityList(Pager pager,Activity activity){
//根据搜索条件获得Activity列表的相关数据
DataModel<Activity> data=activityService.getActivityList(pager,activity);
//创建ModelAndView对象
ModelAndView mav=new ModelAndView("/jsp/activity/activity.jsp");
//把数据放入ModelAndView
mav.addObject("activityList", data.getRows());
mav.addObject("pager", data.getPager());
mav.addObject("activity", activity);
return mav;
}
}
这是Service包下的:
package com.hsaipin.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.hsaipin.dao.ActivityDao;
import com.hsaipin.model.Activity;
import com.hsaipin.model.DataModel;
import com.hsaipin.model.Pager;
import com.hsaipin.service.ActivityService;
@Service("activityService")
public class ActivityServiceImpl implements ActivityService{
@Resource
private ActivityDao activityDao;
@Override
public DataModel<Activity> getActivityList(Pager pager, Activity activity) {
//1.创建DataModel类型对象
DataModel<Activity> data =new DataModel<Activity>();
//2.查数据
//(1)根据搜索条件分页查询Activity列表
List<Activity> list=activityDao.findActivity(pager,activity);
//(2)根据搜索条件获得符合条件Activity数目
//3.把数据放入DataModel类型对象
data.setRows(list);
data.setPager(pager);
return data;
}
}
还有接口:
package com.hsaipin.service;
import com.hsaipin.model.Activity;
import com.hsaipin.model.DataModel;
import com.hsaipin.model.Pager;
public interface ActivityService {
DataModel<Activity> getActivityList(Pager pager, Activity activity);
}
这是dao包下的:
<?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.hsaipin.dao.ActivityDao">
<select id="findActivity" resultType="com.hsaipin.model.Activity">
SELECT * FROM car_activity
limit #{pager.from},#{pager.pageSize}
</select>
</mapper>
接口:
package com.hsaipin.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.hsaipin.model.Activity;
import com.hsaipin.model.Pager;
public interface ActivityDao {
List<Activity> findActivity(@Param("pager")Pager pager,@Param("activity") Activity activity);
}
这是model:
package com.hsaipin.model;
public class Activity {
private Integer a_id; //活动 id
private String a_name; //活动名称
private String content; //活动内容
private String start_time; //开始时间
private String end_time; //结束时间
private String create; //创建者
private Integer is_del; //是否删除 0未删 1删除
public Integer getA_id() {
return a_id;
}
public void setA_id(Integer a_id) {
this. a_id= a_id;
}
public String getA_name() {
return a_name;
}
public void setA_name(String a_name) {
this.a_name = a_name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getStart_time() {
return start_time;
}
public void setStart_time(String start_time) {
this.start_time = start_time;
}
public String getEnd_time() {
return end_time;
}
public void setEnd_time(String end_time) {
this.end_time = end_time;
}
public String getCreate() {
return create;
}
public void setCreate(String create) {
this.create = create;
}
public Integer getIs_del() {
return is_del;
}
public void setIs_del(Integer is_del) {
this.is_del = is_del;
}
}
页面,数据都有,数据库也连好了,为啥没数据啊?
我相信你这样提问题,没几个人能帮你定位问题的,没有数据,原因可能在任何一个环节,即使你把java代码贴出来,那xml配置文件呢?具体sql的写法呢?页面查询传值过程呢?这些都没有,怎么帮你?
一般这种问题最好是自己用工具debug,一步一步走下去,是最快的解决办法了。
你这样别人怎么给你看呀,自己一步步debug,先看dao层有没有从DB取出数据,service层有没有赋值,控制层响应报文里面有值没,前端页面有没有接受到,接受到了是不是没有解析绑定到html上,自己一步步看哈