本帖最后由 yupl007 于 2013-07-31 11:20:46 编辑

解决方案 »

  1.   

    就是有点不清楚这个offenceID怎么来的 我在看别人写的  然后自己照着写了一个 我把代码都贴出来 你们帮我看看 
      

  2.   

    实体类public class OffenceInfo implements Serializable { private static final long serialVersionUID = 1L; private Long offenceID; // ID
    private String idCard;  
    private String plateno; 
    private String epType; 
    private Date illegalTime;  
    private String address; 
    private String illegalAction; 
    private Long illegalType; 
    private String source; 
    private Double fine; 
    private Integer points; 
    private Long deptid; 
    private String re;
    public Long getOffenceID() {
    return offenceID;
    } public void setOffenceID(Long offenceID) {
    this.offenceID = offenceID;
    } public String getIdCard() {
    return idCard;
    } public void setIdCard(String idCard) {
    this.idCard = idCard;
    } public String getPlateno() {
    return plateno;
    } public void setPlateno(String plateno) {
    this.plateno = plateno;
    }
    public String getEpType() {
    return epType;
    } public void setEpType(String epType) {
    this.epType = epType;
    } public Date getIllegalTime() {
    return illegalTime;
    } public void setIllegalTime(Date illegalTime) {
    this.illegalTime = illegalTime;
    } public String getAddress() {
    return address;
    } public void setAddress(String address) {
    this.address = address;
    } public String getIllegalAction() {
    return illegalAction;
    } public void setIllegalAction(String illegalAction) {
    this.illegalAction = illegalAction;
    } public Long getIllegalType() {
    return illegalType;
    } public void setIllegalType(Long illegalType) {
    this.illegalType = illegalType;
    } public String getSource() {
    return source;
    } public void setSource(String source) {
    this.source = source;
    } public Double getFine() {
    return fine;
    } public void setFine(Double fine) {
    this.fine = fine;
    } public Integer getPoints() {
    return points;
    } public void setPoints(Integer points) {
    this.points = points;
    } public String getRe() {
    return re;
    } public void setRe(String re) {
    this.re = re;
    } public Long getDeptid() {
    return deptid;
    } public void setDeptid(Long deptid) {
    this.deptid = deptid;
    }}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="Mapper.Offence">
    <resultMap id="get-offence-result" type="offenceInfo">
    <result property="offenceID" column="offenceID" jdbcType="BIGINT" javaType="java.lang.Long"/>
    <result property="idCard" column="idCard" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="plateno" column="plateno" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="epType" column="epType" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="illegalTime" column="illegalTime" jdbcType="DATE" javaType="java.sql.Timestamp"/>
    <result property="address" column="address" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="illegalAction" column="illegalAction" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="illegalType" column="illegalType" jdbcType="BIGINT" javaType="java.lang.Long"/>
    <result property="source" column="source" jdbcType="VARCHAR" javaType="java.lang.String"/>
    <result property="fine" column="fine" jdbcType="DECIMAL" javaType="java.lang.Double"/>
    <result property="points" column="points" jdbcType="INTEGER" javaType="java.lang.Integer"/>
    <result property="deptid" column="deptid" jdbcType="BIGINT" javaType="java.lang.Long"/>
    <result property="re" column="re" jdbcType="VARCHAR" javaType="java.lang.String"/>
    </resultMap>

    <sql id="whereOffence">
    <where>
    <if test="driver.drivername != null">
    <![CDATA[
    and idCard in (select id_card from jy_fingerprint.driver where name like '%${driver.drivername}%')
    ]]>
    </if>
    <if test="offence.plateno != null">
    and plateno = #{offence.plateno}
    </if>
    <if test="offence.epType != null">
    and epType = #{offence.epType}
    </if>
    <if test="offence.illegalType != null">
    <![CDATA[
    and illegalType = #{offence.illegalType}
    ]]>
    </if>
    <if test="dateFrom != null">
    <![CDATA[
    and illegalTime > #{dateFrom}
    ]]>
    </if>
    <if test="dateTo != null">
    <![CDATA[
    and illegalTime <= #{dateTo}
    ]]>
    </if>
    <if test="offence.deptid != null">
    <![CDATA[
    and deptid in (select node.id from jy_unpn.dept as node, jy_unpn.dept as parent 
                 where node.lft between parent.lft and parent.rgt and parent.id=#{offence.deptid})
    ]]>
    </if>
    </where>
    </sql>

    <insert id="insertOffence" parameterType="offenceInfo" keyProperty="offenceID"  useGeneratedKeys="true">
    <![CDATA[
    insert into jy_unpn.Tbl_OffenceInfo (idCard,plateno,epType,illegalTime,address,illegalAction,illegalType,source,fine,points,deptid,re) 
    values (#{idCard},#{plateno},#{epType},#{illegalTime},#{address},#{illegalAction},#{illegalType},#{source},#{fine},#{points},#{deptid},#{re})
    ]]>
    </insert>

    <update id="updateOffence" parameterType="offenceInfo">
    <![CDATA[
    update jy_unpn.Tbl_OffenceInfo
    ]]>
    <set>
    <if test="idCard != null">
    idCard = #{idCard},
    </if>
    <if test="plateno != null">
    plateno = #{plateno},
    </if>
    <if test="epType != null">
    epType = #{epType},
    </if>
    <if test="illegalTime != null">
    illegalTime = #{illegalTime},
    </if>
    <if test="address != null">
    address = #{address},
    </if>
    <if test="illegalAction != null">
    illegalAction = #{illegalAction},
    </if>
    <if test="illegalType != null">
    illegalType = #{illegalType},
    </if>
    <if test="source != null">
    source = #{source},
    </if>
    <if test="fine != null">
    fine = #{fine},
    </if>
    <if test="points != null">
    points = #{points},
    </if>
    <if test="deptid != null">
    deptid = #{deptid},
    </if>
    <if test="reamrk != null">
    reamrk = #{reamrk}
    </if>
    </set>
    where offenceID = #{offenceID}
    </update>

    <delete id="deleteOffence" parameterType="offenceInfo">
    <![CDATA[
    delete from jy_unpn.Tbl_OffenceInfo where offenceID = #{offenceID}
    ]]>
    </delete>

    <select id="getOffenceById" parameterType="offenceInfo" resultType="offenceInfo">
    <![CDATA[
    select offenceID,idCard,plateno,epType,illegalTime,address,illegalAction,illegalType,source,fine,points,deptid,re from jy_unpn.Tbl_OffenceInfo
    where offenceID = #{offenceID}
    ]]>
    </select>

    <select id="getOffenceCount" parameterType="offenceVO" resultType="java.lang.Integer">
    <![CDATA[
    select count(*) from jy_unpn.Tbl_OffenceInfo
    ]]>
    <include refid="whereOffence"/>
    </select>

    <select id="getOffenceList" parameterType="offenceVO" resultMap="get-offence-result">
    <include refid="Common.PagePrefix" />
    <![CDATA[
    select offenceID,idCard,plateno,epType,illegalTime,address,illegalAction,illegalType,source,fine,points,deptid,re from jy_unpn.Tbl_OffenceInfo
    ]]>
    <include refid="whereOffence"/>
    order by illegalTime desc
    <include refid="Common.PageSuffix" />
    </select>
    </mapper>执行Servicepublic class OffenceService implements IOffenceService {
    @Resource(name="offenceDao")
        private IOffenceDao offenceDao;
    @Resource(name="deptDao")
    private IDeptDao deptDao;
    @Resource(name="driverDao")
    private IDriverDao driverDao;
    @Override
    public void saveOffence(OffenceInfo offence) throws Exception {
    offenceDao.saveOffence(offence);
    } @Override
    public void updateOffence(OffenceInfo offence) throws Exception {
    offenceDao.updateOffence(offence);
    } @Override
    public void deleteOffence(OffenceInfo offence) throws Exception {
       offenceDao.deleteOffence(offence);
    } @Override
    public OffenceInfo getOffenceById(OffenceInfo offence) throws Exception {

    return offenceDao.getOffenceById(offence);
    } @Override
    public int getOffenceCount(OffenceVO offenceVO) throws Exception {

    return offenceDao.getOffenceCount(offenceVO);
    } @Override
    public List<OffenceVO> getOffenceList(OffenceVO offenceVO)
    throws Exception {
    List<OffenceInfo> alist  =offenceDao.getOffenceList(offenceVO);
    List<OffenceVO> volist  = null;
    if (alist != null &&alist.size()>0 ) {
    volist = new ArrayList<OffenceVO>();
    for(OffenceInfo off : alist){
    OffenceVO  offvo = new OffenceVO();
    offvo.setOffence(off);
    //判断部门是否为空
    if(off.getDeptid() != null){
    Dept dept = new Dept();
    dept.setDeptid(off.getDeptid());
    dept = deptDao.getDeptById(dept);
    offvo.setDept(dept);
    }
    //查询驾驶员
    String idCard = off.getIdCard();
    if(StringUtils.isNotBlank(idCard))
    {
    Driver driver = new Driver();
    driver.setId_card(idCard);
    driver = driverDao.getDriverByIdCard(driver);
    offvo.setDriver(driver);
    }
    volist.add(offvo);
    }
    }
    return volist;
    }
    }
      

  3.   

    实体类是不能那样传值,而且是无法获取到的。貌似LZ是用struts2实现后台?那么可以在action定义该实体的对象实例,然后经过set,get后,就可以获取到。
      

  4.   

    别人写的没有在Action中实例化 然后他的就能删除 很纠结 不知道怎么回事
      

  5.   

    1. 如果你要用 request.getParameter("offenceID");的话, 那说明这个offenceID是你从前端传过去, 至少在某个地方给他赋值并发送请求了;
    2. 如果是用struts的话, 那么你应该也有在前端或者某个地方给他赋值了, 然后在action中set、get实体类的对象, 然后通过对象的get方法就可以取到该值了
      

  6.   

    先确定offenceID是不是实体,感觉不应该是实体。
      

  7.   

    上面的代码看了,建议先理一下现在的流程,看offenceID在哪赋值的,它只是一个简单的变量,并不是你讲的实体。
      

  8.   

    谢谢  已经解决了 在list()方法中 忘记写 Map<String, String> hidden = new LinkedHashMap<String, String>();
    hidden.put("offenceVO.offence.offenceID", "违章信息ID");
    this.getRequest().setAttribute("hidden", hidden);
    他是在这里把offenceID传到页面的