数据库
– Table structure for tb_house_inter
DROP TABLE IF EXISTS tb_house_inter
;
CREATE TABLE tb_house_inter
(
inter_id
int(11) NOT NULL AUTO_INCREMENT,
house_id
int(11) DEFAULT NULL COMMENT ‘对应房源id’,
bed
tinyint(4) DEFAULT NULL COMMENT ‘床:0无1有’,
washing
tinyint(4) DEFAULT NULL COMMENT ‘洗衣机:0无1有’,
air
tinyint(4) DEFAULT NULL COMMENT ‘空调0无1有’,
balcony
tinyint(4) DEFAULT NULL COMMENT ‘阳台:0无1有’,
ice
tinyint(4) DEFAULT NULL COMMENT ‘冰箱:0无1有’,
toilet
tinyint(4) DEFAULT NULL COMMENT ‘卫生间:0无1有’,
kitchen
tinyint(4) DEFAULT NULL COMMENT ‘厨房:0无1有’,
tv
tinyint(4) DEFAULT NULL COMMENT ‘电视:0无1有’,
heater
tinyint(4) DEFAULT NULL COMMENT ‘热水器:0无1有’,
wardrobe
tinyint(4) DEFAULT NULL COMMENT ‘衣柜:0无1有’,
heating
tinyint(4) DEFAULT NULL COMMENT ‘暖气:0无1有’,
internet
tinyint(4) DEFAULT NULL COMMENT ‘宽带:0无1有’,
sofa
tinyint(4) DEFAULT NULL COMMENT ‘沙发:0无1有’,
create_time
bigint(15) DEFAULT NULL COMMENT ‘创建时间’,
update_time
bigint(15) DEFAULT NULL COMMENT ‘更新时间’,
PRIMARY KEY (inter_id
),
UNIQUE KEY tb_house_inter_inter_id_uindex
(inter_id
),
KEY inter_houseid
(house_id
),
CONSTRAINT inter_houseid
FOREIGN KEY (house_id
) REFERENCES tb_house
(house_id
) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
– Records of tb_house_inter
INSERT INTO tb_house_inter
VALUES (‘1’, ‘10013’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘2’, ‘10014’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘3’, ‘10015’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘4’, ‘10016’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘5’, ‘10017’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘6’, ‘10018’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘7’, ‘10019’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘8’, ‘10020’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘9’, ‘10021’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘10’, ‘10022’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘0’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘11’, ‘10023’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘12’, ‘10024’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, null, null);
INSERT INTO tb_house_inter
VALUES (‘15’, ‘10041’, ‘0’, ‘0’, ‘0’, ‘1’, ‘1’, ‘0’, ‘0’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1562498010623’, ‘1562498010623’);
INSERT INTO tb_house_inter
VALUES (‘16’, ‘10042’, ‘0’, ‘0’, ‘1’, ‘0’, ‘1’, ‘0’, ‘0’, ‘1’, ‘0’, ‘1’, ‘1’, ‘1’, ‘0’, ‘1562547325058’, ‘1562547325058’);
INSERT INTO tb_house_inter
VALUES (‘17’, ‘10043’, ‘0’, ‘0’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1562551806218’, ‘1562551806218’);
INSERT INTO tb_house_inter
VALUES (‘19’, ‘10045’, ‘1’, ‘1’, ‘0’, ‘1’, ‘0’, ‘0’, ‘0’, ‘0’, ‘0’, ‘1’, ‘0’, ‘0’, ‘1’, ‘1562572577168’, ‘1562572577168’);
二.实体类
HouseInter
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 +
‘}’;
}
}
三.housePost3.jsp
interface IHouseViewDao
void postHouseInter(HouseInter houseInter);
interface IHouseViewService
void postHouseInter(HouseInter houseInter);
class HouseViewService
@Override
public void postHouseInter(HouseInter houseInter) {
houseViewDao.postHouseInter(houseInter);
}
HouseViewController
@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 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();
}