目录
一、创建pojo并在数据库导入数据
1.在数据库导入数据
数据库表名:
表结构:
2.创建pojo
(1)创建一个BasePojo(ItemCat里面没有新增时间和更新时间属性,这两个属性被抽取出来放在BasePojo中了)
package com.taotao.manager.pojo;
import java.io.Serializable;
import java.util.Date;
public abstract class BasePojo implements Serializable {
private Date created;
private Date updated;
getter/setter方法...
}
(2)创建一个数据库中tb_item_cat表对应的ItemCat类
package com.taotao.manager.pojo;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "tb_item_cat")
public class ItemCat extends BasePojo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "parent_id")
private Long parentId;
private String name;
private Integer status;
@Column(name = "sort_order")
private Integer sortOrder;
@Column(name = "is_parent")
private Boolean isParent;
getter/setter方法...
}
二、通用mapper+分页助手
(1)编写mapper
package com.taotao.manager.mapper;
import com.github.abel533.mapper.Mapper;
import com.taotao.manager.pojo.ItemCat;
public interface ItemCatMapper extends Mapper<ItemCat> {
}
(2)编写Service接口
package com.taotao.manager.service;
import java.util.List;
import com.taotao.manager.pojo.ItemCat;
public interface ItemCatService {
public List<ItemCat> queryItemCatByPage(Integer id,Integer row);
}
(3)编写Service实现类
package com.taotao.manager.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.taotao.manager.mapper.ItemCatMapper;
import com.taotao.manager.pojo.ItemCat;
import com.taotao.manager.service.ItemCatService;
@Service
public class ItemCatServiceImpl implements ItemCatService {
@Autowired
private ItemCatMapper itemCatMapper;
@Override
public List<ItemCat> queryItemCatByPage(Integer page, Integer row) {
// TODO Auto-generated method stub
PageHelper.startPage(page, row);
List<ItemCat> list = this.itemCatMapper.select(null);
return list;
}
}
(4)编写Controller
package com.taotao.manager.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.taotao.manager.pojo.ItemCat;
import com.taotao.manager.service.ItemCatService;
@Controller
@RequestMapping("item/cat")
public class ItemCatController {
@Autowired
private ItemCatService itemCatService;
@RequestMapping("query/{page}")
@ResponseBody
public List<ItemCat> queryItemCat(@PathVariable Integer page,@RequestParam("row") Integer rows){
return this.itemCatService.queryItemCatByPage(page,rows);
}
}
(5)在服务层做服务暴露和在表现层做服务调用
①taotao-manager中的applicationContext-service.xml中添加如下
<!-- 查询所有商品类目 -->
<dubbo:service interface="com.taotao.manager.service.ItemCatService"
ref="itemCatServiceImpl" />
②taotao-manager-web中的springmvc.xml中添加如下
<!-- 调用服务:查询所有商品类目 -->
<dubbo:reference interface="com.taotao.manager.service.ItemCatService"
id="itemCatService" timeout="1000000" />
(7)测试
成功!!!
三、通用页面跳转
(1)导入静态资源(taotao-manager-web的src/main目录下)
(2)配置视图解析器(前面配过了)
(3)编写Controller
package com.taotao.manager.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("page")
public class PageController {
@RequestMapping("{pageName}")
public String toPage(@PathVariable String pageName) {
return pageName;
}
}
(4)测试
成功!!!
四、使用域名访问后台系统
1.修改hosts文件
2.使用nginx代理
(1)先将项目中的服务层的端口号改为81(之前是80,nginx待会也会配置成80会冲突)
taotao-parent的pom文件
(2)解压nginx压缩包
(3)更改配置文件 conf/nginx.conf
(4)运行nginx
三个命令
启动: start nginx.exe
停止: nginx.exe –s stop
重载: nginx.exe –s reload
观察到出现两个进程,运行成功
(5)测试
成功!!!