三期_day05_Dao层的准备工作_II

原创 2015年07月09日 09:04:04

工作目录:



实体类:UserInfo.java 

package com.yc.crm.entity;

import java.util.Date;

public class UserInfo {
	
    private Integer uid;

    private String email;

    private String passwords;

    private String cname;

    private String phone;

    private Integer sex;

    private Integer age;

    private String address;

    private Integer level;

    private Integer pl;

    private Business bussiness;

    private Date createdate;

	public Integer getUid() {
		return uid;
	}

	public void setUid(Integer uid) {
		this.uid = uid;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPasswords() {
		return passwords;
	}

	public void setPasswords(String passwords) {
		this.passwords = passwords;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Integer getPl() {
		return pl;
	}

	public void setPl(Integer pl) {
		this.pl = pl;
	}

	public Business getBussiness() {
		return bussiness;
	}

	public void setBussiness(Business bussiness) {
		this.bussiness = bussiness;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@Override
	public String toString() {
		return "UserInfo [uid=" + uid + ", email=" + email + ", passwords="
				+ passwords + ", cname=" + cname + ", phone=" + phone
				+ ", sex=" + sex + ", age=" + age + ", address=" + address
				+ ", level=" + level + ", pl=" + pl + ", bussiness="
				+ bussiness + ", createdate=" + createdate + "]";
	}

}


2.配置文件UserInfoMapper.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="com.yc.crm.mapper.UserInfoMapper">

	<resultMap id="BaseResultMap" type="com.yc.crm.entity.UserInfo">
		<id column="CRM_ID" property="uid" />
		<result column="EMAIL" property="email" />
		<result column="PASSWORDS" property="passwords" />
		<result column="CNAME" property="cname" />
		<result column="PHONE" property="phone" />
		<result column="SEX" property="sex" />
		<result column="AGE" property="age" />
		<result column="ADDRESS" property="address" />
		<result column="USERLEVEL" property="level" />
		<result column="PL" property="pl" />
		<result column="CREATEDATE" property="createdate" />
		<association property="bussiness"
			resultMap="com.yc.crm.mapper.BusinessMapper.BaseResultMap" />
	</resultMap>

	<delete id="deleteUserByUid" parameterType="int">
		delete crm_user_info where crm_id=#{uid}
	</delete>
	
	<update id="modify" parameterType="UserInfo">
	update crm_user_info 
	<set> 
	<if test="passwords!=null and passwords!=''">
	passwords=#{passwords},
    </if> 
    phone=#{phone},sex=#{sex},"AGE"=#{age},userlevel=#{level},address=#{address} where email=#{email}
	</set>
	</update>
	
	<select id="getUserInfoById" parameterType="int" resultMap="BaseResultMap">
		select * from crm_user_info u join crm_business b on
		u.bussiness_id=b.business_id where u.crm_id=#{id}
	</select>
	
	<select id="vailEmail" resultType="int">
	select count(*) from crm_user_info where email=#{email}
	</select>

	<select id="findUser" parameterType="UserInfo" resultMap="BaseResultMap">
		select * from crm_user_info u join crm_business b on
		u.bussiness_id=b.business_id where u.email=#{email} and
		u.passwords=#{passwords}
	</select>

	<update id="updateUserInfoDate" parameterType="UserInfo">
	update crm_user_info set createdate=sysdate where email=#{email}
	</update>
	
	<insert id="insertUserInfo" parameterType="UserInfo">
		<selectKey resultType="int" order="BEFORE" keyProperty="uid">
			SELECT SEQ_CRM_USER_INFO_SEQ.Nextval  from DUAL
		</selectKey>
		insert into crm_user_info values(#{uid},#{email},#{passwords},#{cname},#{phone},#{sex},#{age},#{address},#{level},#{pl},#{bussiness.businessId},sysdate)
	</insert>

</mapper>


 

3.与配置文件对应的接口UserInfoMapper.java

package com.yc.crm.mapper;

import com.yc.crm.entity.UserInfo;

public interface UserInfoMapper {
    UserInfo getUserInfoById(int id);
    int insertUserInfo(UserInfo userInfo);
	UserInfo findUser(UserInfo userInfo);
	int updateUserInfoDate(UserInfo userInfo);
	int vailEmail(String email);
	int modify(UserInfo userInfo);
	int deleteUserByUid(int uid);
}

4.测试类  

package com.yc.crm.test.conn;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.yc.crm.biz.UserInfoService;
import com.yc.crm.entity.Business;
import com.yc.crm.entity.UserInfo;
import com.yc.crm.utils.Encrypt;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class TestUserInfoImplTest {

	@Autowired
	private UserInfoService userInfoService;

	@Test
	public void testDelete(){
		UserInfo ui=new UserInfo();
		ui.setUid(84);
		int result=userInfoService.deleteUserInfo(ui);
		System.out.println(result);
	}
	
	/*
	 * UserInfo [uid=1116, email=testadd6@qq.com,
	 * passwords=900150983cd24fb0d6963f7d28e17f72, cname=测试添加6,
	 * phone=15211441233, sex=1, age=21, address=USCofChina, level=0, pl=0,
	 * bussiness=Business [businessId=104, businessName=奔驰4S,
	 * businessType=<200], createdate=Wed Jun 24 16:47:02 CST 2015]
	 */
	@Test
	public void testModify() {
		UserInfo ui = userInfoService.getInfo(1116);
		ui.setAddress("这是新的,看看能成功吗");
		ui.setPasswords("hehe");
		ui = userInfoService.modify(ui);
		System.out.println(ui);
	}

	@Test
	public void testVailEmail() {
		int re = userInfoService.vailEmail("chenjian@qq.com");
		System.out.println(re);
	}

	@Test
	public void testLogin() {
		UserInfo ui = new UserInfo();
		ui.setEmail("chenjian@qq.com");
		ui.setPasswords(Encrypt.md5("abc"));
		ui = userInfoService.login(ui);
		System.out.println(ui);
	}

	@Test
	public void testGetUserInfoById() {
		UserInfo ui = userInfoService.getInfo(1116);
		System.out.println(ui);
	}

	@Test
	public void testInsertUserInfo() {
		UserInfo userinfo = new UserInfo();
		userinfo.setAddress("纽约");
		userinfo.setAge(23);
		Business b = new Business();
		b.setBusinessId(102);
		userinfo.setBussiness(b);
		userinfo.setCname("淡定淡定淡定");
		userinfo.setEmail("che@qq.com");
		userinfo.setLevel(4);
		userinfo.setPasswords("abc");
		userinfo.setPhone("15544778788");
		userinfo.setPl(0);
		userinfo.setSex(0);
		System.out.println(userinfo);
		boolean isSucccess = userInfoService.register(userinfo, 1005);
		int id = userinfo.getUid();
		System.out.println("isSucccess is :" + isSucccess);
		System.out.println("id is :" + id);
	}
}

已经完成了Dao层和Model层,Service和Action层后面在总结。


我是菜鸟,我在路上。


版权声明:have a nice day!

相关文章推荐

ANSYS经典_M05准备工作

  • 2012年11月12日 10:12
  • 580KB
  • 下载

uCOS-II在MSP430上的移植1——准备工作

uC/OS-II在MSP430上的移植1——准备工作 学习uC/OS-II有一段时间了,下了上百兆的资料。网上可以找到很多移植好的工程,参考别人的,稍微修改下,编译调试通过了,用起来始终觉得...

三期_day09_信息+订单管理_II

一年之计在于春,一日之计在于晨,一家之和在于和,一生之计在于勤。                                                                    ...
  • cjvs9k
  • cjvs9k
  • 2015年07月11日 18:19
  • 573

Oracle 11g安装准备工作

  • 2014年12月16日 22:42
  • 851KB
  • 下载

矢量化槽探素描图的准备工作

  • 2014年03月24日 15:55
  • 324KB
  • 下载

21天战拖记——Day12:番茄工作法:如何做到要是第一(2014-05-15)

今天跑到南湖理学院那边和陆老师聊了很久,对于自己的不足也有了相当的认识。什么都想搞,结果什么都不精通,还是要打基础,慢一点不要紧,一步一个脚印地来,其实满就是快。否则以后再回来更吃亏。明天开始搬去南湖...

量产U盘准备工作

  • 2013年04月01日 21:57
  • 22KB
  • 下载

国产InitPHP框架系列 - InitPHP框架搭建高可用WEB应用05:数据层Dao使用

InitPHP框架是一款轻量级PHP开源框架,框架文档和下载地址:http://initphp.com Dao层说明 Dao层通俗的讲就是数据层。再简单的讲,Dao层主要是用于写sql语句的。可能...
  • initphp
  • initphp
  • 2014年11月29日 09:39
  • 4697

oracle安装前准备工作中的安装包

  • 2007年07月24日 18:01
  • 2.33MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:三期_day05_Dao层的准备工作_II
举报原因:
原因补充:

(最多只允许输入30个字)