这次是个完整的易居,可实现登录、注册、拦截、图片轮播等功能
结构、代码如下
代码如下
Collect.java
package com.yiju.bean;
/**
* 收藏类
*/
public class Collect {
private int collId; //收藏记录的唯一标识ID
private int userId; //用户ID
private int houseId; //用户收藏的房源ID
private int isDelete; //是否删除 0-未删除 1-已删除
private long createTime; //创建时间
private long updateTime; //更新时间
public int getCollId() {
return collId;
}
public void setCollId(int collId) {
this.collId = collId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getHouseId() {
return houseId;
}
public void setHouseId(int houseId) {
this.houseId = houseId;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "Collect{" +
"collId=" + collId +
", userId=" + userId +
", houseId=" + houseId +
", isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
House.java
package com.yiju.bean;
import java.math.BigDecimal;
/**
* 房屋表
*/
public class House {
private int houseId; //房源表唯一标识ID
private int userId; //发布此房源的用户ID
private int houseType; //房源类型 0:新房 1:旧房 2:租房
private String houseTitle; //房源帖子标题
private String houseHeadimg; //房源帖子头像
private String housePlanimg1; //房屋户型平面图1 外键
private String housePlanimg2; //房屋户型平面图2 外键
private String houseImg1; //房源室内图1
private String houseImg2; //房源室内图2
private String houseImg3; //房源室内图3
private String houseImg4; //房源室内图4
private String houseImg5; //房源室内图5
private String houseImg6; //房源室内图6
private BigDecimal housePrice; //房源预计售价
private String priceUnit; //售价单位 元/每月 元/每套 元/每年
private String houseAddress; //房源地址
private int isDelete; //0:未删除 1:已删除
private long createTime; //创建时间
private long updateTime; //更新时间
public int getHouseId() {
return houseId;
}
public void setHouseId(int houseId) {
this.houseId = houseId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getHouseType() {
return houseType;
}
public void setHouseType(int houseType) {
this.houseType = houseType;
}
public String getHouseTitle() {
return houseTitle;
}
public void setHouseTitle(String houseTitle) {
this.houseTitle = houseTitle;
}
public String getHouseHeadimg() {
return houseHeadimg;
}
public void setHouseHeadimg(String houseHeadimg) {
this.houseHeadimg = houseHeadimg;
}
public String getHousePlanimg1() {
return housePlanimg1;
}
public void setHousePlanimg1(String housePlanimg1) {
this.housePlanimg1 = housePlanimg1;
}
public String getHousePlanimg2() {
return housePlanimg2;
}
public void setHousePlanimg2(String housePlanimg2) {
this.housePlanimg2 = housePlanimg2;
}
public String getHouseImg1() {
return houseImg1;
}
public void setHouseImg1(String houseImg1) {
this.houseImg1 = houseImg1;
}
public String getHouseImg2() {
return houseImg2;
}
public void setHouseImg2(String houseImg2) {
this.houseImg2 = houseImg2;
}
public String getHouseImg3() {
return houseImg3;
}
public void setHouseImg3(String houseImg3) {
this.houseImg3 = houseImg3;
}
public String getHouseImg4() {
return houseImg4;
}
public void setHouseImg4(String houseImg4) {
this.houseImg4 = houseImg4;
}
public String getHouseImg5() {
return houseImg5;
}
public void setHouseImg5(String houseImg5) {
this.houseImg5 = houseImg5;
}
public String getHouseImg6() {
return houseImg6;
}
public void setHouseImg6(String houseImg6) {
this.houseImg6 = houseImg6;
}
public BigDecimal getHousePrice() {
return housePrice;
}
public void setHousePrice(BigDecimal housePrice) {
this.housePrice = housePrice;
}
public String getPriceUnit() {
return priceUnit;
}
public void setPriceUnit(String priceUnit) {
this.priceUnit = priceUnit;
}
public String getHouseAddress() {
return houseAddress;
}
public void setHouseAddress(String houseAddress) {
this.houseAddress = houseAddress;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "House{" +
"houseId=" + houseId +
", userId=" + userId +
", houseType=" + houseType +
", houseTitle='" + houseTitle + '\'' +
", houseHeadimg='" + houseHeadimg + '\'' +
", housePlanimg1='" + housePlanimg1 + '\'' +
", housePlanimg2='" + housePlanimg2 + '\'' +
", houseImg1='" + houseImg1 + '\'' +
", houseImg2='" + houseImg2 + '\'' +
", houseImg3='" + houseImg3 + '\'' +
", houseImg4='" + houseImg4 + '\'' +
", houseImg5='" + houseImg5 + '\'' +
", houseImg6='" + houseImg6 + '\'' +
", housePrice=" + housePrice +
", priceUnit='" + priceUnit + '\'' +
", houseAddress='" + houseAddress + '\'' +
", isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
HouseInfo.java
package com.yiju.bean;
/**
* 房屋信息表
*/
public class HouseInfo {
private int infoId; //房源详细信息表唯一标识ID
private int houseId; //对应房源表唯一ID
private String houseNature; //房源性质:商品房 住宅房
private String houseModel; //普通式住宅 公寓式住宅 别墅 独栋
private int houseYear; //房源建造时间
private String houseValid; //房源期限: 70年、100年、永久
private String houseLayout; //房源户型:几室几厅几卫
private String houseArea; //房源面积
private String houseTurn; //朝向
private int houseFloor; //楼层
private int floorAll; //总楼层
private String houseDecorate; //装饰类型:精装 简装
private String houseLift; //是否有电梯: 0无 1有
private long createTime; //创建时间
private long updateTime; //更新时间
public int getInfoId() {
return infoId;
}
public void setInfoId(int infoId) {
this.infoId = infoId;
}
public int getHouseId() {
return houseId;
}
public void setHouseId(int houseId) {
this.houseId = houseId;
}
public String getHouseNature() {
return houseNature;
}
public void setHouseNature(String houseNature) {
this.houseNature = houseNature;
}
public String getHouseModel() {
return houseModel;
}
public void setHouseModel(String houseModel) {
this.houseModel = houseModel;
}
public int getHouseYear() {
return houseYear;
}
public void setHouseYear(int houseYear) {
this.houseYear = houseYear;
}
public String getHouseValid() {
return houseValid;
}
public void setHouseValid(String houseValid) {
this.houseValid = houseValid;
}
public String getHouseLayout() {
return houseLayout;
}
public void setHouseLayout(String houseLayout) {
this.houseLayout = houseLayout;
}
public String getHouseArea() {
return houseArea;
}
public void setHouseArea(String houseArea) {
this.houseArea = houseArea;
}
public String getHouseTurn() {
return houseTurn;
}
public void setHouseTurn(String houseTurn) {
this.houseTurn = houseTurn;
}
public int getHouseFloor() {
return houseFloor;
}
public void setHouseFloor(int houseFloor) {
this.houseFloor = houseFloor;
}
public int getFloorAll() {
return floorAll;
}
public void setFloorAll(int floorAll) {
this.floorAll = floorAll;
}
public String getHouseDecorate() {
return houseDecorate;
}
public void setHouseDecorate(String houseDecorate) {
this.houseDecorate = houseDecorate;
}
public String getHouseLift() {
return houseLift;
}
public void setHouseLift(String houseLift) {
this.houseLift = houseLift;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "HouseInfo{" +
"infoId=" + infoId +
", houseId=" + houseId +
", houseNature='" + houseNature + '\'' +
", houseModel='" + houseModel + '\'' +
", houseYear=" + houseYear +
", houseValid='" + houseValid + '\'' +
", houseLayout='" + houseLayout + '\'' +
", houseArea='" + houseArea + '\'' +
", houseTurn='" + houseTurn + '\'' +
", houseFloor=" + houseFloor +
", floorAll=" + floorAll +
", houseDecorate='" + houseDecorate + '\'' +
", houseLift='" + houseLift + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
HouseInter.java
package com.yiju.bean;
/**
* 出租房屋内饰表
*/
public class HouseInter {
private int interId; //内饰表ID
private int houseId; //对应房源id
private int bed; //床:0无 1有
private int washing; //洗衣机:0无 1有
private int air; //空调: 0无 1有
private int balcony; //阳台:0无 1有
private int ice; //冰箱:0无 1有
private int toilet; //卫生间:0无 1有
private int kitchen; //厨房:0无 1有
private int tv; //电视:0无 1有
private int heater; //热水器:0无 1有
private int wardrobe; //衣柜:0无 1有
private int heating; //暖气:0无 1有
private int internet; //宽带:0无 1有
private int sofa; //沙发:0无 1有
private long createTime; //创建时间
private long updateTime; //更新时间
public int getInterId() {
return interId;
}
public void setInterId(int interId) {
this.interId = interId;
}
public int getHouseId() {
return houseId;
}
public void setHouseId(int houseId) {
this.houseId = houseId;
}
public int getBed() {
return bed;
}
public void setBed(int bed) {
this.bed = bed;
}
public int getWashing() {
return washing;
}
public void setWashing(int washing) {
this.washing = washing;
}
public int getAir() {
return air;
}
public void setAir(int air) {
this.air = air;
}
public int getBalcony() {
return balcony;
}
public void setBalcony(int balcony) {
this.balcony = balcony;
}
public int getIce() {
return ice;
}
public void setIce(int ice) {
this.ice = ice;
}
public int getToilet() {
return toilet;
}
public void setToilet(int toilet) {
this.toilet = toilet;
}
public int getKitchen() {
return kitchen;
}
public void setKitchen(int kitchen) {
this.kitchen = kitchen;
}
public int getTv() {
return tv;
}
public void setTv(int tv) {
this.tv = tv;
}
public int getHeater() {
return heater;
}
public void setHeater(int heater) {
this.heater = heater;
}
public int getWardrobe() {
return wardrobe;
}
public void setWardrobe(int wardrobe) {
this.wardrobe = wardrobe;
}
public int getHeating() {
return heating;
}
public void setHeating(int heating) {
this.heating = heating;
}
public int getInternet() {
return internet;
}
public void setInternet(int internet) {
this.internet = internet;
}
public int getSofa() {
return sofa;
}
public void setSofa(int sofa) {
this.sofa = sofa;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "HouseInter{" +
"interId=" + interId +
", houseId=" + houseId +
", bed=" + bed +
", washing=" + washing +
", air=" + air +
", balcony=" + balcony +
", ice=" + ice +
", toilet=" + toilet +
", kitchen=" + kitchen +
", tv=" + tv +
", heater=" + heater +
", wardrobe=" + wardrobe +
", heating=" + heating +
", internet=" + internet +
", sofa=" + sofa +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
UserAuth.java
package com.yiju.bean;
/**
* 用户认证实体类
*/
public class UserAuth {
private int authId; //认证id
private int userId; //用户id
private String userName; //用户姓名
private int userGender; //性别
private String userCard; //身份证号码
private String userCardAddress; //身份证住址
private String userLiveAddress; //住址
private String userCarding; //证件照
private String userPropertyimg; //房产证照片
private int authStatus;//认证状态
private int isDelete; //是否已删除 0-未删除 1-已删除
private long createTime; //创建时间
private long updateTime; //更新时间
public int getAuthId() {
return authId;
}
public void setAuthId(int authId) {
this.authId = authId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getUserGender() {
return userGender;
}
public void setUserGender(int userGender) {
this.userGender = userGender;
}
public String getUserCard() {
return userCard;
}
public void setUserCard(String userCard) {
this.userCard = userCard;
}
public String getUserCardAddress() {
return userCardAddress;
}
public void setUserCardAddress(String userCardAddress) {
this.userCardAddress = userCardAddress;
}
public String getUserLiveAddress() {
return userLiveAddress;
}
public void setUserLiveAddress(String userLiveAddress) {
this.userLiveAddress = userLiveAddress;
}
public String getUserCarding() {
return userCarding;
}
public void setUserCarding(String userCarding) {
this.userCarding = userCarding;
}
public String getUserPropertyimg() {
return userPropertyimg;
}
public void setUserPropertyimg(String userPropertyimg) {
this.userPropertyimg = userPropertyimg;
}
public int getAuthStatus() {
return authStatus;
}
public void setAuthStatus(int authStatus) {
this.authStatus = authStatus;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "UserAuth{" +
"authId=" + authId +
", userId=" + userId +
", userName='" + userName + '\'' +
", userGender=" + userGender +
", userCard='" + userCard + '\'' +
", userCardAddress='" + userCardAddress + '\'' +
", userLiveAddress='" + userLiveAddress + '\'' +
", userCarding='" + userCarding + '\'' +
", userPropertyimg='" + userPropertyimg + '\'' +
", authStatus=" + authStatus +
", isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
UserInfo.java
package com.yiju.bean;
public class UserInfo {
public UserInfo() {
}
public UserInfo(int userId, String nickname, String truename, int gender, String city, long createTime) {
this.userId = userId;
this.nickname = nickname;
this.truename = truename;
this.gender = gender;
this.city = city;
this.createTime = createTime;
}
private int userId; //用户id
private String phone; //用户手机号,用于登录
private String password; //密码
private String email; //邮箱
private String nickname; //昵称
private String truename; //真实姓名
private int gender; //性别 0:男 1:女
private String province; //省份
private String city; //城市
private int isDelete; //是否删除 0:未删除 1:已删除
private long createTime; //创建时间
private long updateTime; //更新时间
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getTruename() {
return truename;
}
public void setTruename(String truename) {
this.truename = truename;
}
public int getGender() {
return gender;
}
public void setGender(int gender) {
this.gender = gender;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "UserInfo{" +
"userId=" + userId +
", phone='" + phone + '\'' +
", password='" + password + '\'' +
", email='" + email + '\'' +
", nickname='" + nickname + '\'' +
", truename='" + truename + '\'' +
", gender=" + gender +
", province='" + province + '\'' +
", city='" + city + '\'' +
", isDelete=" + isDelete +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}
HouseViewController.java
package com.yiju.controller;
import com.github.pagehelper.PageInfo;
import com.yiju.bean.House;
import com.yiju.bean.HouseInfo;
import com.yiju.bean.HouseInter;
import com.yiju.pojo.HouseView;
import com.yiju.service.IHouseViewService;
import com.yiju.util.YijuUtil;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Controller
@RequestMapping("house")
public class HouseViewController {
@Autowired
private IHouseViewService houseViewService;
//显示新|旧|租 房推荐的4条数据
@RequestMapping("findFourHouse.do")
public ModelAndView findFourHouse(){
ModelAndView mv=new ModelAndView();
List<HouseView> newHouses = houseViewService.findFourHouseByType(0);
List<HouseView> oldHouses = houseViewService.findFourHouseByType(1);
List<HouseView> rentHouses = houseViewService.findFourHouseByType(2);
mv.addObject("newHouses",newHouses);
mv.addObject("oldHouses",oldHouses);
mv.addObject("rentHouses",rentHouses);
mv.setViewName("../main");
return mv;
}
//点击图片 h3 跳转房屋详情页面
@RequestMapping("findHouseById")
public ModelAndView findHouseById(int houseId){
ModelAndView mv=new ModelAndView();
HouseView house= houseViewService.findHouseByHouseId(houseId);
mv.addObject("houseInfo",house);
mv.setViewName("details");
return mv;
}
@RequestMapping("findHouse.do")
public ModelAndView findHouse(@RequestParam(defaultValue = "1") int currentPage, int houseType ){
ModelAndView mv=new ModelAndView();
// 房子的所有数据
List<HouseView> houses = houseViewService.findHouseByType(currentPage,houseType);
//推荐房源数据
List<HouseView> fh = houseViewService.findFourHouseByType(houseType);
//把houses放到分页中
PageInfo<HouseView> pageInfo=new PageInfo<>(houses);
mv.addObject("pageInfo",pageInfo);
mv.addObject("fh",fh);
mv.addObject("houseType",houseType);
mv.setViewName("houses");
return mv;
}
@RequestMapping("toHousePost2.do")
public ModelAndView toHousePost2(@Param(value = "houseTitle") String houseTitle,
@Param(value = "houseAddress") String houseAddress,
@Param(value = "housePrice") BigDecimal housePrice,
@Param(value = "priceUnit") String priceUnit,
@Param(value = "houseHeadimg") MultipartFile houseHeadimg,
@Param(value = "housePlanimg1") MultipartFile housePlanimg1,
@Param(value = "housePlanimg2") MultipartFile housePlanimg2,
@Param(value = "houseImg1") MultipartFile houseImg1,
@Param(value = "houseImg2") MultipartFile houseImg2,
@Param(value = "houseImg3") MultipartFile houseImg3,
@Param(value = "houseImg4") MultipartFile houseImg4,
@Param(value = "houseImg5") MultipartFile houseImg5,
@Param(value = "houseImg6") MultipartFile houseImg6,
HttpSession session
) throws IOException {
House house=new House();
house.setHouseTitle(houseTitle);
house.setHouseAddress(houseAddress);
house.setHousePrice(housePrice);
house.setPriceUnit(priceUnit);
house.setUserId(10007);
Map<String, byte[]> images=new HashMap<>();
if ( houseHeadimg.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseHeadimg.getBytes());
}
if (housePlanimg1.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,housePlanimg1.getBytes());
}
if (housePlanimg2.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,housePlanimg2.getBytes());
}
if (houseImg1.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg1.getBytes());
}
if (houseImg2.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg2.getBytes());
}
if (houseImg3.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg3.getBytes());
}
if (houseImg4.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg4.getBytes());
}
if (houseImg5.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg5.getBytes());
}
if (houseImg6.getSize()!=0){
String picName= YijuUtil.getPicName();
house.setHouseHeadimg(picName);
images.put(picName,houseImg6.getBytes());
}
session.setAttribute("house",house);
session.setAttribute("images",images);
// Set<String> keys=images.keySet();
// for (String key:keys){
// MultipartFile file=images.get(key);
// YijuUtil.upload(file.getBytes(),key);
// }
// houseViewService.postHouse(house);
ModelAndView mv=new ModelAndView();
mv.setViewName("housePost2");
return mv;
}
@RequestMapping("responsePost2.do")
@ResponseBody
public String responsePost2(HouseInfo houseInfo,HttpSession session){
// houseInfo.setHouseId(10001);
// houseViewService.postHouseInfo(houseInfo);
session.setAttribute("houseInfo",houseInfo);
return new JSONObject().toString();
}
@RequestMapping("responsePost3.do")
@ResponseBody
public String responsePost3(HouseInter houseInter,HttpSession session){
// houseInter.setHouseId(10013);
// houseViewService.postHouseInter(houseInter);
session.setAttribute("houseInter",houseInter);
return new JSONObject().toString();
}
@RequestMapping("doHousePost.do")
public String doHousePost(HttpSession session) throws IOException {
House house= (House) session.getAttribute("house");
Map<String,byte[]> images= (Map<String, byte[]>) session.getAttribute("images");
HouseInfo houseInfo= (HouseInfo) session.getAttribute("houseInfo");
HouseInter houseInter= (HouseInter) session.getAttribute("houseInter");
houseViewService.postHouse(house);
Set<String> keys=images.keySet();
for (String key:keys){
byte[] bytes=images.get(key);
//MultipartFile file=images.get(key);
YijuUtil.upload(bytes,key);
}
houseInfo.setHouseId(house.getHouseId());
houseViewService.postHouseInfo(houseInfo);
houseInter.setHouseId(house.getHouseId());
houseViewService.postHouseInter(houseInter);
return "redirect:findHouseById.do?houseId="+house.getHouseId();
}
}
UserController.java
package com.yiju.controller;
import com.yiju.bean.Collect;
import com.yiju.bean.UserAuth;
import com.yiju.bean.UserInfo;
import com.yiju.pojo.CollectView;
import com.yiju.service.IUserService;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("login2.do")
@ResponseBody
public String login2(@Param(value = "phone") String phone,
@Param(value = "password") String password,
HttpSession session) {
JSONObject jsonObject = new JSONObject();
UserInfo user = userService.findByPhone(phone);
if (user == null) {
jsonObject.put("result", "0");
} else if (!password.equals(user.getPassword())) {
jsonObject.put("result", "1");
} else {
session.setAttribute("user",user);
jsonObject.put("result", "2");
}
return jsonObject.toString();
}
@RequestMapping("singup.do")
@ResponseBody
public String singup(@Param(value = "phone") String phone,
@Param(value = "password") String password) {
//1.看一下该手机有没有注册
//2.已经有了 就提示该用户已经注册,跳转到登入页面
//3.没有 就注册
JSONObject jsonObject = new JSONObject();
UserInfo user = userService.findByPhone(phone);
if (user == null) {
userService.add(phone, password);
jsonObject.put("result", "0");
} else {
jsonObject.put("result", "1");
}
return jsonObject.toString();
}
@RequestMapping("saveEdit.do")
@ResponseBody
public String saveEdit(UserInfo userInfo,HttpSession session ) {
JSONObject jsonObject = new JSONObject();
UserInfo userInfo1= (UserInfo) session.getAttribute("user");
userInfo1.setTruename(userInfo.getTruename());
userInfo1.setNickname(userInfo.getNickname());
userInfo1.setGender(userInfo.getGender());
userInfo1.setCity(userInfo.getCity());
userService.updateUserInfo(userInfo1);
session.setAttribute("user",userInfo1);
return jsonObject.toString();
}
@RequestMapping("login.do")
@ResponseBody
public String login(@Param(value = "username") String username,
@Param(value = "password") String password) {
if ("123".equals(username) && "123".equals(password)) {
return "success";
}
return "failure";
}
@RequestMapping("login1.do")
@ResponseBody
public String login1(@Param(value = "username") String username,
@Param(value = "password") String password) {
JSONObject jsonObject = new JSONObject();
if ("123".equals(username) && "123".equals(password)) {
jsonObject.put("result", "1");
//{result:1,result:2}
} else {
jsonObject.put("result", "2");
}
return jsonObject.toString();
}
@RequestMapping("verify.do")
public ModelAndView verify(HttpSession session) {
UserInfo user= (UserInfo) session.getAttribute("user");
UserAuth userAuth = userService.findUserAuth(user.getUserId());
session.setAttribute("userAuth",userAuth);
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("verify");
return modelAndView;
}
@RequestMapping("saveAuth.do")
@ResponseBody
public String saveAuth(HttpSession session,UserAuth userAuth ){
UserInfo user= (UserInfo) session.getAttribute("user");
userAuth.setUserName(user.getTruename());
userAuth.setUserGender(user.getGender());
userAuth.setUserId(user.getUserId());
userAuth.setCreateTime(new Date().getTime());
userAuth.setUpdateTime(new Date().getTime());
userService.postUserAuth(userAuth);
return new JSONObject().toString();
}
@RequestMapping("deleteAuth.do")
public ModelAndView deleteAuth(HttpSession session ){
UserInfo user= (UserInfo) session.getAttribute("user");
userService.deleteById(user.getUserId());
ModelAndView modelAndView=new ModelAndView();
modelAndView.setViewName("personal");
return modelAndView;
}
@RequestMapping("upps.do")
@ResponseBody
public String upps(HttpSession session,String oldpassword,String password ){
UserInfo user= (UserInfo) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
if(!user.getPassword().equals(oldpassword)){
jsonObject.put("result",1);
}else {
user.setPassword(password);
userService.updatePS(user);
session.setAttribute("user",user);
jsonObject.put("result",2);
}
return jsonObject.toString();
}
@RequestMapping("favorite.do")
public ModelAndView favorite(HttpSession session){
UserInfo user= (UserInfo) session.getAttribute("user");
ModelAndView modelAndView=new ModelAndView();
List<CollectView> collcets = userService.getCollectViewByUser(user.getUserId());
modelAndView.addObject("collcets",collcets);
modelAndView.setViewName("favorite");
return modelAndView;
}
@RequestMapping("addToCollect.do")
@ResponseBody
public String addToCollect(HttpSession session,int houseId){
UserInfo user= (UserInfo) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
Collect c = userService.findByHouseType(user.getUserId(), houseId);
if(c!=null){
jsonObject.put("result","0");
}else {
Collect collect=new Collect();
collect.setUserId(user.getUserId());
collect.setHouseId(houseId);
collect.setUpdateTime(new Date().getTime());
collect.setCreateTime(new Date().getTime());
userService.addCollect(collect);
jsonObject.put("result","1");
}
return jsonObject.toString();
}
}
IHouseViewDao.java
package com.yiju.dao;
import com.yiju.bean.House;
import com.yiju.bean.HouseInfo;
import com.yiju.bean.HouseInter;
import com.yiju.pojo.HouseView;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IHouseViewDao {
List<HouseView> findFourHouseByType(@Param("houseType") int houseType);//显示4个房源类型
HouseView findHouseByHouseById(int houseId);//房源表唯一标识ID
List<HouseView> findHouseByType(@Param("houseType")int houseType);//显示全部房源类型
void postHouse(House house);
void postHouseInfo(HouseInfo houseInfo);
void postHouseInter(HouseInter houseInter);
}
IUserDao.java
package com.yiju.dao;
import com.yiju.bean.Collect;
import com.yiju.bean.UserAuth;
import com.yiju.bean.UserInfo;
import com.yiju.pojo.CollectView;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IUserDao {
UserInfo findUserByPhone(String phone);
void singup(@Param("phone") String phone, @Param("password") String password);
void updateUserInfo(UserInfo userInfo);
UserAuth findUserAuthByUserId(int userId);
void postUserAuthor(UserAuth userAuth);
void deleteById(int userId);
void updatePS(UserInfo userInfo);
List<CollectView> getCollectViewByUser(int userId);
void addCollect(Collect collect);
Collect findByHouseType(@Param("userId") int userId , @Param("houseId") int houseId);
}
CollectView.java
package com.yiju.pojo;
public class CollectView {
private int collId;
private int userId;
private int houseId;
private int idDelete;
private long createTime;
private long updateTime;
private String houseTitle;
private String houseHeadimg;
private String houseAddress;
public int getCollId() {
return collId;
}
public void setCollId(int collId) {
this.collId = collId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getHouseId() {
return houseId;
}
public void setHouseId(int houseId) {
this.houseId = houseId;
}
public int getIdDelete() {
return idDelete;
}
public void setIdDelete(int idDelete) {
this.idDelete = idDelete;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(long updateTime) {
this.updateTime = updateTime;
}
public String getHouseTitle() {
return houseTitle;
}
public void setHouseTitle(String houseTitle) {
this.houseTitle = houseTitle;
}
public String getHouseHeadimg() {
return houseHeadimg;
}
public void setHouseHeadimg(String houseHeadimg) {
this.houseHeadimg = houseHeadimg;
}
public String getHouseAddress() {
return houseAddress;
}
public void setHouseAddress(String houseAddress) {
this.houseAddress = houseAddress;
}
@Override
public String toString() {
return "CollectView{"
版权声明:本文为kou_13原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。