数据从数据库到java代码再到前台页面展示流程
(以线索管理模块为例)
somao_api >>>APP 端
somao_common >>>工具类
somao_domain >>>实体类
somao_mybatis >>>dao impl service
somao_web >>>{java–>controller}、{resources—>xml}、{webapp—>html css..}
1.实体类domain
public class Clue{
...
}
2.接口dao
public interface ClueDao{
...
}
3.mapper xml 文件
.--->
4.实现类 daoImpl
@Repository
@SuppressWarnings("unchecked")
public class ClueDaoImpl implements ClueDao{
@Autowired
private DaoSupport dao;
@Override
public List findAll(Page page) {
return (List) dao.findForList("ClueMapper.listPageaClue", page);
}
}
5.服务类 service
@Service
@Transactional
public class ClueService{
@Autowired
private ClueDao clueDao;
...
}
6.控制器 Controller
@Controller
@RequestMapping("/crm/clue")
public class ClueController extends BaseController{
@Autowired
public ClueDao clueDao;
@RequestMapping("search")-->/crm/clue/search
@ResponseBody
JSONObject search(HttpServletRequest request, HttpServletResponse response, Page page) {
JSONObject json = new JSONObject();
System.out.println();
String keyword = request.getParameter("keyword");
String pageNo = request.getParameter("page");
String size = request.getParameter("size");
User user = (User) request.getSession().getAttribute("fuser");
String accountsArr=request.getParameter("accountsArr");
String contactTypeArr=request.getParameter("contactTypeArr");
String levelArr=request.getParameter("levelArr");
List str=null;
List contactStr=null;
List levelStr=null;
List pageresult = null;
if (!StringUtils.isEmpty(page) && !StringUtils.isEmpty(size)) {
PageData pd = new PageData();
page.setCurrentPage(Integer.parseInt(pageNo));
page.setShowCount(Integer.parseInt(size));
pd.put("userId", user.getId());
pd.put("userCmpyId", user.getCmpyId());
if(keyword.equals("待联系")){
pd.put("progress", 0);
}else if(keyword.equals("联系中")){
pd.put("progress", 1);
}else if(keyword.equals("转客跟进")){
pd.put("progress", 2);
}else if(keyword.equals("成单")){
pd.put("progress", 3);
}else if(keyword.equals("放弃")){
pd.put("progress", 4);
}else if(keyword.equals("搜猫推荐")){
pd.put("type", 1);
}else if(keyword.equals("用户自建")){
pd.put("type", 2);
}else{
pd.put("keyword", keyword);
}
pd.put("userType", user.getUserType());
pd.put("userGroupId", user.getUserGroupId());
if((accountsArr!="")&&(accountsArr!=null)){
if(accountsArr.indexOf(',')==-1){
str=new ArrayList<>();
str.add(accountsArr);
}else{
String[] arr=accountsArr.split(",");
str=Arrays.asList(arr);
}
}
if((levelArr!="")&&(levelArr!=null)){
if(levelArr.indexOf(',')==-1){
levelStr=new ArrayList<>();
levelStr.add(levelArr);
}else{
String[] arr=levelArr.split(",");
levelStr=Arrays.asList(arr);
}
}
if((contactTypeArr!="")&&(contactTypeArr!=null)){
if(contactTypeArr.indexOf(',')==-1){
contactStr=new ArrayList<>();
contactStr.add(contactTypeArr);
}else{
String[] arr=contactTypeArr.split(",");
contactStr=Arrays.asList(arr);
}
}
pd.put("levelStr", levelStr);
pd.put("contactStr", contactStr);
pd.put("ids", str);
page.setPd(pd);
pageresult = clueDao.findAll(page);
}
json.put("content", pageresult);
json.put("page", page);
return json;
}
}
============
CrmMainController.java
@RequestMapping("cluemanage")
public ModelAndView cluemanage(HttpServletRequest request,HttpServletResponse response) {
ModelAndView mv=this.getModelAndView("cluemanage", JModelAndView.CRM_PATH, request, response);
return mv;
}
7.页面 html
cluemanage.html
<td colspan="11">没有记录,请更换查询条件,<button class='btn' ng-click="init();">重置搜索条件button>td>
8.JavaScript js
ClueController.js
4. $scope.getcluelist = function(page,size,srckeyword){
$scope.keyword = srckeyword;
5. var url = 'crm/clue/search?'; [*
var t_url = url + 'page=' + page + '&size=' + size+'&keyword=' +
($scope.keyword||""+'&accountsArr='+
($scope.accountsArr))+'&contactTypeArr='+
($scope.contactTypeArr)+'&levelArr='+
($scope.levelArr);
t_url=encodeURI(t_url);
$http.get(t_url).success(function (data) {
console.log(data);
if(data.content.length>0){
$scope.clues = data.content;
$scope.page = data;
$scope.page.size = data.page.showCount;
$scope.page.url = url;
$scope.page.first = data.page.first;
$scope.page.last = data.page.last;
$scope.page.number = data.page.currentPage;
$scope.page.numberOfElements = data.content.length;
$scope.page.totalElements = data.page.totalResult;
$scope.page.totalPages = data.page.totalPage;
$scope.currentPage=data.page.currentPage;
}else{
if(data.page.totalPage>0){
$scope.page.pagefunction($scope.page.number-1,$scope.page.size);
}else{
$scope.clues = data.content;
$scope.page = data;
$scope.page.size = data.page.showCount;
$scope.page.url = url;
$scope.page.first = data.page.first;
$scope.page.last = data.page.last;
$scope.page.number = data.page.currentPage;
$scope.page.numberOfElements = data.content.length;
$scope.page.totalElements = data.page.totalResult;
$scope.page.totalPages = data.page.totalPage;
$scope.currentPage=data.page.currentPage;
}
}
$scope.page.pagefunction = function(page, size){
var deferred = $q.defer();
$http({
method: "GET",
'url': url + 'page=' + page + '&size=' + size+ '&keyword=' +
($scope.keyword||"")+
'&accountsArr='+
($scope.accountsArr)+'&contactTypeArr='+
($scope.contactTypeArr)+'&levelArr='+
($scope.levelArr)
})
.success(function(data, status) {
deferred.resolve(data);
});
deferred.promise.then(function (data) {
$scope.clues = data.content;
$scope.page.size = data.page.showCount;
$scope.page.url = url;
$scope.page.first = data.page.first;
$scope.page.last = data.page.last;
$scope.page.number = data.page.currentPage;
$scope.page.numberOfElements = data.content.length;
$scope.page.totalElements = data.page.totalResult;
$scope.page.totalPages = data.page.totalPage;
$scope.currentPage=data.page.currentPage;
}, function (data) {
console.log(data);
});
}
});
}
2. $scope.init = function(){
$scope.accountsArr='';
$scope.contactTypeArr='';
$scope.levelArr='';
3. $scope.getcluelist(0,10,'');
$http.get('crm/potentuser/findProvince').success(function (data) {
$scope.provinces=data;
});
$("#searchContactType").find("ul li").each(function(){
$(this).removeClass("checked");
});
}
1. $scope.init();