mapper.xml文件頭
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.neuedu.mapper.EmpMapper">
</mapper>
結構
<!--java下mapper位置-->
<mapper namespace="com.neuedu.mapper.???Mapper">
<!--查--> <!--方法名--> <!--參數(shù)類型--> <!--返回值類型-->
<select id = "serchByEmpno" parametmeterType = "Integer" resultType = "com.neuedu.pojo.Emp">
select * from emp where empno = #{value}
</select>
<!--增-->
<insert parameterType="Registlevel" id="add">
insert into registlevel (RegistCode,RegistName,SequenceNo,RegistFee,RegistQuota) values (#{registcode},#{registname},#{sequenceno},#{registfee},#{registquota})
</insert>
<!--改+動態(tài)sql-->
<update parameterType="Registlevel" id="set">
update registlevel
<set>
<if test="registcode != null"> RegistCode = #{registcode}, </if>
<if test="registname != null"> RegistName = #{registname}, </if>
<if test="sequenceno != null"> SequenceNo = #{sequenceno}, </if>
<if test="registfee != null"> RegistFee = #{registfee}, </if>
<if test="registquota != null"> RegistQuota = #{registquota}, </if>
<if test="delmark != null"> DelMark = #{delmark}, </if>
</set>
where ID = #{id}
</update>
<!--查map和模糊查詢及分頁-->
<select resultType="map" parameterType="com.neuedu.hisdemo2.utils.PageUtils" id="selectAll">
select * from registlevel where DelMark != 0
<if test="#{registlevelstr} != null"> and (RegistCode like '%${registlevelstr}%' or RegistName like '%${registlevelstr}%') </if>
limit #{pageIndex},#{pageSize}
</select>
</mapper>
resources中
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--配置-->
<configuration>
<properties resource="db.properties"></properties>
<!--類型別名-->
<typeAliases>
<package name="com.xxxxx.pojo"/>
</typeAliases>
<!--development(開發(fā) 固定這么寫)-->
<environments default="development">
<environment id="development">
<!--事務管理器類型 為jdbc-->
<transactionManager type="JDBC"></transactionManager>
<!--數(shù)據(jù)源為合并數(shù)據(jù)-->
<dataSource type="POOLED">
<!--性質-->
<property name="driver" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<!--映射-->
<mappers>
<package name="com.xxxxx.mapper"/>
</mappers>
</configuration>
log4j.properties
# Global logging configuration
# 在開發(fā)環(huán)境日志級別要設置為DEBUG怎抛、生產環(huán)境要設置為INFO或者ERROR
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
db.properties
jdbc.driverClassName = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://localhost:3306/fly?useUnicode=true&characterEncoding=utf8
jdbc.username = root
jdbc.password = root
<resultMap type="saleChance" id="saleChanceResultMap">
<id column="chanceId" property="chanceId"/>
<result column="chanceSource" property="chanceSource"/>
<result column="chanceCustName" property="chanceCustName"/>
<result column="chanceTitle" property="chanceTitle"/>
<result column="chanceRate" property="chanceRate"/>
<result column="chanceLinkman" property="chanceLinkman"/>
<result column="chanceTel" property="chanceTel"/>
<result column="chanceDesc" property="chanceDesc"/>
<result column="chanceCreateId" property="chanceCreateId"/>
<result column="chanceCreateDate" property="chanceCreateDate"/>
<result column="chanceDueId" property="chanceDueId"/>
<result column="chanceDueDate" property="chanceDueDate"/>
<result column="chanceStatus" property="chanceStatus"/>
<association property="sysUser" javaType="sysUser">
<id column="userId" property="userId"/>
<result column="chanceDueName" property="userName"/>
<result column="chanceCreateName" property="userName"/>
</association>
</resultMap>
<select id="selectSaleInfoById" parameterType="SaleChance" resultMap = "saleChanceResultMap">
select sa.*,sy.username chanceCreateName,s.username chanceDueName
from salechance sa
join sysuser s
on s.userId = sa.chanceCreateId
join sysuser sy
on sy.userId = sa.chanceDueId
where chanceId = #{chanceId}
</select>
public class SaleChance {
//加上要連接的表的實體類對象屬性
private SysUser sysUser;
public SysUser getSysUser() {
return sysUser;
}
public void setSysUser(SysUser sysUser) {
this.sysUser = sysUser;
}
}