(001) java后台开发之流程初识

java 后台开发流程

这篇文章为了奠基一下被我打入冷宫两个月左右的iOS开发,因为之前由于iOS项目停止的原因,被调至后台开发,两个月中也学习到了很多关于Java、sql、js、jsp的内容,感谢我的同事悉心指教!

eclipse(编程工具)+navicat(数据库)+zookeeper(服务协调)=开发环境,大致的开发流程如下:

1、数据库建表

2、新建实体类

3、新建Dao并测试Dao,需要配置Mapper(xml)

4、新建Service接口(定义接口)

5、Service接口的实现并测试,需要配置dubbo注册service生产者

6、新建controller,需要配置dubbo注册service消费者

7、前端页面(js、jsp)

8、起服务并调试


1、数据库建表

1)一般在表结构中添加int类型的id作为表的主键,并设置为自增长。

2)需要注意控制好字段的长度、是否可以为null,并注释。


2、新建实体类

  1. package com.clt.wsxc.commons.domain.mp;  
  2.   
  3. import java.util.Date;  
  4.   
  5. import com.alibaba.fastjson.annotation.JSONField;  
  6. import com.clt.wsxc.commons.domain.Pagination;  
  7.   
  8. /** 
  9.  *@Description: 微信关注统计实体类 
  10.  *@Author:YXQ 
  11.  *@Since:2015年6月16日 
  12.  */  
  13. public class WechatBind extends Pagination{  
  14.       
  15.     private static final long serialVersionUID = 8262554316156565954L;  
  16.   
  17.     // 主键id  
  18.     private int bindId;  
  19.       
  20.     // 类型 1001:跑男 ,1002:用户  
  21.     private String type;  
  22.       
  23.     private String typeStr;  
  24.       
  25.     // 被扫描者编号  
  26.     private String number;  
  27.       
  28.     // 被扫描者姓名  
  29.     private String name;  
  30.       
  31.     // 扫描者的微信openid  
  32.     private String openId;  
  33.       
  34.     // 扫描者是否消费 0未消费 1已消费  
  35.     private int haveConsumed;  
  36.       
  37.     private String haveConsumedStr;  
  38.       
  39.     // 扫描者姓名  
  40.     private String consumerName;  
  41.       
  42.     // 扫描者电话  
  43.     private String consumerPhone;  
  44.       
  45.     // 更新时间  
  46.     @JSONField(format = "yyyy-MM-dd HH:mm:ss")  
  47.     private Date createTime;  
  48.   
  49.     public int getBindId() {  
  50.         return bindId;  
  51.     }  
  52.   
  53.     public void setBindId(int bindId) {  
  54.         this.bindId = bindId;  
  55.     }  
  56.   
  57.     public String getType() {  
  58.         return type;  
  59.     }  
  60.   
  61.     public void setType(String type) {  
  62.         this.type = type;  
  63.     }  
  64.   
  65.     public String getTypeStr() {  
  66.         int i = Integer.valueOf(this.type);  
  67.         if(i == 1001){  
  68.             typeStr = "跑男";  
  69.         }else if(i == 1002){  
  70.             typeStr = "用户";  
  71.         }else{  
  72.             typeStr = "其他";  
  73.         }  
  74.         return typeStr;  
  75.     }  
  76.   
  77.     public void setTypeStr(String typeStr) {  
  78.         this.typeStr = typeStr;  
  79.     }  
  80.   
  81.     public String getNumber() {  
  82.         return number;  
  83.     }  
  84.   
  85.     public void setNumber(String number) {  
  86.         this.number = number;  
  87.     }  
  88.   
  89.     public String getName() {  
  90.         return name;  
  91.     }  
  92.   
  93.     public void setName(String name) {  
  94.         this.name = name;  
  95.     }  
  96.   
  97.     public String getOpenId() {  
  98.         return openId;  
  99.     }  
  100.   
  101.     public void setOpenId(String openId) {  
  102.         this.openId = openId;  
  103.     }  
  104.   
  105.     public Date getCreateTime() {  
  106.         return createTime;  
  107.     }  
  108.   
  109.     public void setCreateTime(Date createTime) {  
  110.         this.createTime = createTime;  
  111.     }  
  112.   
  113.     public int getHaveConsumed() {  
  114.         return haveConsumed;  
  115.     }  
  116.   
  117.     public void setHaveConsumed(int haveConsumed) {  
  118.         this.haveConsumed = haveConsumed;  
  119.     }  
  120.   
  121.     public String getHaveConsumedStr() {  
  122.         if(this.haveConsumed == 0){  
  123.             haveConsumedStr = "暂未消费";  
  124.         }else{  
  125.             haveConsumedStr = "已消费";  
  126.         }  
  127.         return haveConsumedStr;  
  128.     }  
  129.   
  130.     public void setHaveConsumedStr(String haveConsumedStr) {  
  131.         this.haveConsumedStr = haveConsumedStr;  
  132.     }  
  133.   
  134.     public String getConsumerName() {  
  135.         return consumerName;  
  136.     }  
  137.   
  138.     public void setConsumerName(String consumerName) {  
  139.         this.consumerName = consumerName;  
  140.     }  
  141.   
  142.     public String getConsumerPhone() {  
  143.         return consumerPhone;  
  144.     }  
  145.   
  146.     public void setConsumerPhone(String consumerPhone) {  
  147.         this.consumerPhone = consumerPhone;  
  148.     }  
  149.       
  150.       
  151. }  
package com.clt.wsxc.commons.domain.mp;

import java.util.Date;

import com.alibaba.fastjson.annotation.JSONField;
import com.clt.wsxc.commons.domain.Pagination;

/**
 *@Description: 微信关注统计实体类
 *@Author:YXQ
 *@Since:2015年6月16日
 */
public class WechatBind extends Pagination{
	
	private static final long serialVersionUID = 8262554316156565954L;

	// 主键id
	private int bindId;
	
	// 类型 1001:跑男 ,1002:用户
	private String type;
	
	private String typeStr;
	
	// 被扫描者编号
	private String number;
	
	// 被扫描者姓名
	private String name;
	
	// 扫描者的微信openid
	private String openId;
	
	// 扫描者是否消费 0未消费 1已消费
	private int haveConsumed;
	
	private String haveConsumedStr;
	
	// 扫描者姓名
	private String consumerName;
	
	// 扫描者电话
	private String consumerPhone;
	
	// 更新时间
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	public int getBindId() {
		return bindId;
	}

	public void setBindId(int bindId) {
		this.bindId = bindId;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTypeStr() {
		int i = Integer.valueOf(this.type);
		if(i == 1001){
			typeStr = "跑男";
		}else if(i == 1002){
			typeStr = "用户";
		}else{
			typeStr = "其他";
		}
		return typeStr;
	}

	public void setTypeStr(String typeStr) {
		this.typeStr = typeStr;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public int getHaveConsumed() {
		return haveConsumed;
	}

	public void setHaveConsumed(int haveConsumed) {
		this.haveConsumed = haveConsumed;
	}

	public String getHaveConsumedStr() {
		if(this.haveConsumed == 0){
			haveConsumedStr = "暂未消费";
		}else{
			haveConsumedStr = "已消费";
		}
		return haveConsumedStr;
	}

	public void setHaveConsumedStr(String haveConsumedStr) {
		this.haveConsumedStr = haveConsumedStr;
	}

	public String getConsumerName() {
		return consumerName;
	}

	public void setConsumerName(String consumerName) {
		this.consumerName = consumerName;
	}

	public String getConsumerPhone() {
		return consumerPhone;
	}

	public void setConsumerPhone(String consumerPhone) {
		this.consumerPhone = consumerPhone;
	}
	
	
}

1)实体类一般会继承分页基类pagination(自定义的分页基类,传参数时可以用该基类,返回时需要用PaginationEntity,把对象放在items中)

2)生成serialVersionUID(相当于java类的身份证,主要用于版本控制。Java的序列化机制是通过在运行时判断类的serialVersionUID来验证版本一致性,版本升级时反序列化仍保持对象的唯一性。

3)实体类的字段设为私有,只提供开放的get与set方法,这是为了提高实体类的安全性。

4)Date类型的字段,用@JSONField(format = "yyyy-MM-dd HH:mm:ss")格式化输出。


3、新建Dao并测试Dao,需要配置Mapper(xml)

  1. package com.clt.wsxc.dao.mp;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.springframework.stereotype.Repository;  
  6.   
  7. import com.clt.wsxc.commons.domain.PaginationEntity;  
  8. import com.clt.wsxc.commons.domain.mp.WechatBind;  
  9. import com.clt.wsxc.dao.base.BaseDao;  
  10. /** 
  11.  *@Description: 微信关注统计Dao类 
  12.  *@Author:YXQ 
  13.  *@Since:2015年6月16日 
  14.  */  
  15. @Repository  
  16. public class WechatBindDao extends BaseDao<WechatBind>{  
  17.   
  18.     @Override  
  19.     public void insert(WechatBind domain) {  
  20.         // TODO Auto-generated method stub  
  21.           
  22.     }  
  23.   
  24.     @Override  
  25.     public void update(WechatBind domain) {  
  26.         // TODO Auto-generated method stub  
  27.           
  28.     }  
  29.   
  30.     @Override  
  31.     public void delete(WechatBind domain) {  
  32.         // TODO Auto-generated method stub  
  33.           
  34.     }  
  35.   
  36.     @Override  
  37.     public WechatBind selectOne(WechatBind domain) {  
  38.         // TODO Auto-generated method stub  
  39.         return null;  
  40.     }  
  41.   
  42.     @Override  
  43.     public List<WechatBind> selectList(WechatBind domain) {  
  44.         // TODO Auto-generated method stub  
  45.         return getSqlSession().selectList("mp.WechatBindMapper.selectList", domain);  
  46.     }  
  47.       
  48.     // 查询分页  
  49.     public PaginationEntity<WechatBind> selectPage(WechatBind domain) {  
  50.         List<WechatBind> list = selectList(domain);  
  51.         domain.setIsPaging(true);  
  52.         int count = getSqlSession().selectOne("mp.WechatBindMapper.selectCount",  
  53.                         domain);  
  54.         return new PaginationEntity<WechatBind>(count, list, domain);  
  55.     }  
  56.   
  57. }  
package com.clt.wsxc.dao.mp;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.clt.wsxc.commons.domain.PaginationEntity;
import com.clt.wsxc.commons.domain.mp.WechatBind;
import com.clt.wsxc.dao.base.BaseDao;
/**
 *@Description: 微信关注统计Dao类
 *@Author:YXQ
 *@Since:2015年6月16日
 */
@Repository
public class WechatBindDao extends BaseDao<WechatBind>{

	@Override
	public void insert(WechatBind domain) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(WechatBind domain) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(WechatBind domain) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public WechatBind selectOne(WechatBind domain) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<WechatBind> selectList(WechatBind domain) {
		// TODO Auto-generated method stub
		return getSqlSession().selectList("mp.WechatBindMapper.selectList", domain);
	}
	
	// 查询分页
    public PaginationEntity<WechatBind> selectPage(WechatBind domain) {
        List<WechatBind> list = selectList(domain);
        domain.setIsPaging(true);
        int count = getSqlSession().selectOne("mp.WechatBindMapper.selectCount",
        				domain);
        return new PaginationEntity<WechatBind>(count, list, domain);
    }

}

// Dao

1)Spring注解:@Repository,它用于将数据访问层 (DAO 层 ) 的类标识为 Spring Bean,只需将该注解标注在 DAO类上即可。

2)使用getSqlSession()声明sql语句

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  3. <mapper namespace="mp.WechatBindMapper">  
  4.     <resultMap type="WechatBind" id="WechatBindMap">  
  5.         <result column="bind_id" property="bindId" />  
  6.         <result column="type" property="type" />  
  7.         <result column="number" property="number" />  
  8.         <result column="openId" property="openId" />  
  9.         <result column="createTime" property="create_time" />  
  10.     </resultMap>  
  11.       
  12.     <select id="selectList" parameterType="WechatBind" resultType="WechatBind">  
  13.         select  
  14.             type,  
  15.             bindId,  
  16.             number,  
  17.             openId,  
  18.             createTime,  
  19.             name,  
  20.             consumerName,  
  21.             consumerPhone,  
  22.             userId,  
  23.             haveConsumed  
  24.         from(  
  25.             select   
  26.                 type,  
  27.                 bindId,  
  28.                 number,  
  29.                 openId,  
  30.                 user.createTime,  
  31.                 name,  
  32.                 consumerName,  
  33.                 consumerPhone,  
  34.                 userId,  
  35.                 haveConsumed  
  36.         from  
  37.             (  
  38.             select  
  39.             uw.type type,  
  40.             uw.bind_id bindId,  
  41.             uw.number number,  
  42.             uw.openId openId,  
  43.             uw.create_time createTime,  
  44.             ri.Runman_Name name,  
  45.             ui.User_Name consumerName,  
  46.             ui.User_Phone consumerPhone,  
  47.             ui.User_Id userId,  
  48.             oi.Service_Id haveConsumed  
  49.         from user_wechatbind uw,runman_info ri, user_member um, user_info ui  
  50.         left join order_info oi   
  51.         on ui.User_Id = oi.User_Id  
  52.         where uw.type in (1001, 1002)  
  53.         and uw.number = ri.Runman_Id  
  54.         and uw.openId = um.User_UserName  
  55.         and um.User_Id = ui.User_Id  
  56.         and um.User_Type = 2    
  57.         <if test="name != null and name != ''">and ri.Runman_Name like '%${name}%'</if>  
  58.      ) user  
  59.      left join order_info oi   
  60.      on user.userId = oi.User_Id             
  61. ) t  
  62. group by bindId  
  63. order by number   
  64.     </select>  
  65.       
  66.     <select id="selectCount" parameterType="WechatBind" resultType="Integer">  
  67.         SELECT COUNT(*)  
  68.         FROM user_wechatbind uw  
  69.         where uw.type = 1001  
  70.         or uw.type = 1002  
  71.         <!-- <where>  
  72.             <if test="name != null and name != ''">  
  73.                 and name like '%${name}%'  
  74.             </if>  
  75.         </where> -->  
  76.     </select>  
  77.       
  78. </mapper>  
<?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="mp.WechatBindMapper">
    <resultMap type="WechatBind" id="WechatBindMap">
        <result column="bind_id" property="bindId" />
        <result column="type" property="type" />
        <result column="number" property="number" />
        <result column="openId" property="openId" />
        <result column="createTime" property="create_time" />
    </resultMap>
    
    <select id="selectList" parameterType="WechatBind" resultType="WechatBind">
        select
            type,
            bindId,
            number,
            openId,
            createTime,
            name,
            consumerName,
            consumerPhone,
            userId,
            haveConsumed
        from(
            select 
                type,
                bindId,
                number,
                openId,
                user.createTime,
                name,
                consumerName,
                consumerPhone,
                userId,
                haveConsumed
        from
            (
            select
            uw.type type,
            uw.bind_id bindId,
            uw.number number,
            uw.openId openId,
            uw.create_time createTime,
            ri.Runman_Name name,
            ui.User_Name consumerName,
            ui.User_Phone consumerPhone,
            ui.User_Id userId,
            oi.Service_Id haveConsumed
        from user_wechatbind uw,runman_info ri, user_member um, user_info ui
        left join order_info oi 
        on ui.User_Id = oi.User_Id
        where uw.type in (1001, 1002)
        and uw.number = ri.Runman_Id
        and uw.openId = um.User_UserName
        and um.User_Id = ui.User_Id
        and um.User_Type = 2  
        <if test="name != null and name != ''">and ri.Runman_Name like '%${name}%'</if>
     ) user
     left join order_info oi 
     on user.userId = oi.User_Id           
) t
group by bindId
order by number 
    </select>
    
    <select id="selectCount" parameterType="WechatBind" resultType="Integer">
        SELECT COUNT(*)
        FROM user_wechatbind uw
        where uw.type = 1001
        or uw.type = 1002
        <!-- <where>
            <if test="name != null and name != ''">
                and name like '%${name}%'
            </if>
        </where> -->
    </select>
    
</mapper>


4、新建Service接口(定义接口)

  1. package com.clt.wsxc.api.mp;  
  2.   
  3. import com.clt.wsxc.commons.domain.PaginationEntity;  
  4. import com.clt.wsxc.commons.domain.mp.WechatBind;  
  5. import com.clt.wsxc.commons.exception.extend.BizException;  
  6. import com.clt.wsxc.commons.exception.extend.SystemException;  
  7.   
  8. /** 
  9.  *@Description: 微信关注统计接口 
  10.  *@Author:YXQ 
  11.  *@Since:2015年6月16日 
  12.  */  
  13. public interface WechatBindService {  
  14.     // 分页  
  15.     PaginationEntity<WechatBind> WechatBindPagination(WechatBind wechatBind)throws BizException,SystemException;  
  16. }  
package com.clt.wsxc.api.mp;

import com.clt.wsxc.commons.domain.PaginationEntity;
import com.clt.wsxc.commons.domain.mp.WechatBind;
import com.clt.wsxc.commons.exception.extend.BizException;
import com.clt.wsxc.commons.exception.extend.SystemException;

/**
 *@Description: 微信关注统计接口
 *@Author:YXQ
 *@Since:2015年6月16日
 */
public interface WechatBindService {
	// 分页
	PaginationEntity<WechatBind> WechatBindPagination(WechatBind wechatBind)throws BizException,SystemException;
}
1) 关键字为interface,只需申明方法


5、Service接口的实现并测试,需要配置dubbo注册service生产者

  1. package com.clt.wsxc.provider.mp.service;  
  2.   
  3. import org.slf4j.Logger;  
  4. import org.slf4j.LoggerFactory;  
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.dao.DataAccessException;  
  7.   
  8. import com.clt.wsxc.api.mp.WechatBindService;  
  9. import com.clt.wsxc.commons.domain.PaginationEntity;  
  10. import com.clt.wsxc.commons.domain.mp.WechatBind;  
  11. import com.clt.wsxc.commons.exception.extend.BizException;  
  12. import com.clt.wsxc.commons.exception.extend.SystemException;  
  13. import com.clt.wsxc.commons.exception.message.InternalCode;  
  14. import com.clt.wsxc.commons.exception.message.SystemExceptionMessage;  
  15. import com.clt.wsxc.dao.mp.WechatBindDao;  
  16. /** 
  17.  *@Description: 微信关注统计接口实现 
  18.  *@Author:YXQ 
  19.  *@Since:2015年6月16日 
  20.  */  
  21. public class WechatBindServiceImpl implements WechatBindService{  
  22.     // 内部异常编码,package001,java文件020  
  23.     final String INTERNAL_CODE = "001.020";  
  24.       
  25.     private Logger log= LoggerFactory.getLogger (WechatBindServiceImpl.class);  
  26.       
  27.     @Autowired  
  28.     private WechatBindDao wechatBindDao;  
  29.       
  30.     @Override  
  31.     public PaginationEntity<WechatBind> WechatBindPagination(WechatBind wechatBind) throws BizException, SystemException {  
  32.         PaginationEntity<WechatBind> equPagination = null;  
  33.         try {  
  34.             equPagination = wechatBindDao.selectPage (wechatBind);  
  35.         } catch(DataAccessException e) {  
  36.             e.printStackTrace();  
  37.             log.error(e.toString());  
  38.             throw new SystemException(SystemExceptionMessage.SYSTEM_ERROR, InternalCode.MAN_SERVICE+INTERNAL_CODE+"01"null);  
  39.         } catch (Exception e) {  
  40.             e.printStackTrace();  
  41.             log.error(e.toString());  
  42.             throw new SystemException(SystemExceptionMessage.SYSTEM_ERROR, InternalCode.MAN_SERVICE+INTERNAL_CODE+"02"null);  
  43.         }  
  44.         return equPagination;  
  45.     }  
  46.   
  47. }  
package com.clt.wsxc.provider.mp.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;

import com.clt.wsxc.api.mp.WechatBindService;
import com.clt.wsxc.commons.domain.PaginationEntity;
import com.clt.wsxc.commons.domain.mp.WechatBind;
import com.clt.wsxc.commons.exception.extend.BizException;
import com.clt.wsxc.commons.exception.extend.SystemException;
import com.clt.wsxc.commons.exception.message.InternalCode;
import com.clt.wsxc.commons.exception.message.SystemExceptionMessage;
import com.clt.wsxc.dao.mp.WechatBindDao;
/**
 *@Description: 微信关注统计接口实现
 *@Author:YXQ
 *@Since:2015年6月16日
 */
public class WechatBindServiceImpl implements WechatBindService{
	// 内部异常编码,package001,java文件020
    final String INTERNAL_CODE = "001.020";
	
    private Logger log= LoggerFactory.getLogger (WechatBindServiceImpl.class);
    
    @Autowired
    private WechatBindDao wechatBindDao;
    
	@Override
	public PaginationEntity<WechatBind> WechatBindPagination(WechatBind wechatBind) throws BizException, SystemException {
		PaginationEntity<WechatBind> equPagination = null;
		try {
            equPagination = wechatBindDao.selectPage (wechatBind);
        } catch(DataAccessException e) {
            e.printStackTrace();
            log.error(e.toString());
            throw new SystemException(SystemExceptionMessage.SYSTEM_ERROR, InternalCode.MAN_SERVICE+INTERNAL_CODE+"01", null);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.toString());
            throw new SystemException(SystemExceptionMessage.SYSTEM_ERROR, InternalCode.MAN_SERVICE+INTERNAL_CODE+"02", null);
        }
		return equPagination;
	}

}

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.     http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  7.   
  8. <bean id="wechatBindService" class="com.clt.wsxc.provider.mp.service.WechatBindServiceImpl"/>  
  9.     <dubbo:service interface="com.clt.wsxc.api.mp.WechatBindService" ref="wechatBindService" version="1.0.0" loadbalance="${dubbo.service.loadbalance}" timeout="${dubbo.service.timeout}"/>  
  10.   
  11. </beans>  
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<bean id="wechatBindService" class="com.clt.wsxc.provider.mp.service.WechatBindServiceImpl"/>
    <dubbo:service interface="com.clt.wsxc.api.mp.WechatBindService" ref="wechatBindService" version="1.0.0" loadbalance="${dubbo.service.loadbalance}" timeout="${dubbo.service.timeout}"/>

</beans>

1)关键字implements,包含申明的接口类

6、新建controller,需要配置dubbo注册service消费者

  1. package com.clt.wsxc.mvc.mp.controller.wechatBind;  
  2.   
  3. import org.springframework.beans.factory.annotation.Autowired;  
  4. import org.springframework.stereotype.Controller;  
  5. import org.springframework.web.bind.annotation.RequestMapping;  
  6. import org.springframework.web.bind.annotation.ResponseBody;  
  7.   
  8. import com.clt.wsxc.api.mp.WechatBindService;  
  9. import com.clt.wsxc.commons.domain.PaginationEntity;  
  10. import com.clt.wsxc.commons.domain.mp.WechatBind;  
  11. import com.clt.wsxc.commons.mvc.controller.BaseController;  
  12. /** 
  13.  *@Description: 微信关注统计控制器 
  14.  *@Author:YXQ 
  15.  *@Since:2015年6月16日 
  16.  */  
  17. @Controller  
  18. @RequestMapping("/wechatBind")  
  19. public class WechatBindController extends BaseController{  
  20.     @Autowired  
  21.     private WechatBindService wechatBindService;  
  22.       
  23.     @ResponseBody  
  24.     @RequestMapping("/page")  
  25.     public PaginationEntity<WechatBind> getParamPage(WechatBind wechatBind) throws Exception {  
  26.         // 排序  
  27.         wechatBind.setSortName("name");  
  28.         return wechatBindService.WechatBindPagination(wechatBind);  
  29.     }  
  30. }  
package com.clt.wsxc.mvc.mp.controller.wechatBind;

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.ResponseBody;

import com.clt.wsxc.api.mp.WechatBindService;
import com.clt.wsxc.commons.domain.PaginationEntity;
import com.clt.wsxc.commons.domain.mp.WechatBind;
import com.clt.wsxc.commons.mvc.controller.BaseController;
/**
 *@Description: 微信关注统计控制器
 *@Author:YXQ
 *@Since:2015年6月16日
 */
@Controller
@RequestMapping("/wechatBind")
public class WechatBindController extends BaseController{
	@Autowired
	private WechatBindService wechatBindService;
	
	@ResponseBody
	@RequestMapping("/page")
	public PaginationEntity<WechatBind> getParamPage(WechatBind wechatBind) throws Exception {
		// 排序
		wechatBind.setSortName("name");
		return wechatBindService.WechatBindPagination(wechatBind);
	}
}
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
  8.         http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  9.           
  10.     <dubbo:application name="dubbo-mp-server" />  
  11.       
  12.     <dubbo:registry address="${dubbo.registry.address}" check="false" file="false" />  
  13.   
  14. <!-- 微信关注统计 -->  
  15.     <dubbo:reference id="wechatBindService" interface="com.clt.wsxc.api.mp.WechatBindService" version="1.0.0" check="false" />  
  16.   
  17. </beans>  
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
		
	<dubbo:application name="dubbo-mp-server" />
	
	<dubbo:registry address="${dubbo.registry.address}" check="false" file="false" />

<!-- 微信关注统计 -->
    <dubbo:reference id="wechatBindService" interface="com.clt.wsxc.api.mp.WechatBindService" version="1.0.0" check="false" />

</beans>
1)@controller 注解表示为控制器

2)@RequestMapping 请求路径映射,如果标注在某个controller的类级别上,则表明访问此类路径下的方法都要加上其配置的路径;最常用是标注在方法上,表明哪个具体的方法来接受处理某次请求。

3)继承于BaseController,统一错误日志和异常处理

7、前端页面(js、jsp)

因本人js不是特别拿手,就不多做解释了。

8、起服务并调试

打开本地网址,查看所写页面是否能正常展示。

尝试增删改查等方法(若已实现),查看是否会抛出异常。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值