微信小程序(三)

1)详情中评论、工作经历的数据绑定
2)用户信息的注册,判断用户是否注册过
3)预定工作
4)订单查询

详情中评论、工作经历的数据绑定

评论数据绑定

后台:
		1)确定SQL语句
			select c.time,c.stars,c.content,u.username from tb_comment c , tb_user u
 		   where u.user_id = c.user_id and c.nanny_id = 1;
		2)编写实体类
			参照SQL语句中的字段
		3)编写DAO和其中方法
			 public class CommentDAOImpl implements CommentDAO{
    
    	@Override
    	public List<Comment> findAllCommentsByNannyId(int nannyId) {
    		return JdbcUtils.queryList(Comment.class, 
    				"select c.time,c.stars,c.content,u.username from tb_comment c , tb_user u "
    				+ "where u.user_id = c.user_id and c.nanny_id = ?", nannyId);
    			}    
   		 }
		4)测试
		5)编写servlet
		 @WebServlet("/findComments.do")
    public class FindAllCommentsByNannyServlet extends HttpServlet{
    	
    	@Override
    	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    		//获得nannyId参数
    		int nannyId = Integer.parseInt(req.getParameter("nannyId"));
    		CommentDAO dao = new CommentDAOImpl();
    		List<Comment> list = dao.findAllCommentsByNannyId(nannyId);
    		System.out.println(list);
    		//将集合转换成JSON数组发送给浏览器
    		String json = new Gson().toJson(list);
    		//设置编码,解决中文乱码
    		resp.setContentType("text/html;charset=UTF-8");
    		//通过网络输出流
    		resp.getWriter().print(json);
    	}
    }
		6)测试
		
前端:
		1)在data里定义评论数组变量
			//用于绑定评论的数组变量
				comments:null
		2)在onload中使用wx,request请求后台Servlet
		3)在success使用setData给数组变量赋值
			var _this = this;
			    //请求后台,通过保姆的id查询评论
			    wx.request({
			      url: 'http://localhost:8080/MyNanny/findComments.do?nannyId='+nanny2.nanny_id,
			      success(res){
			        console.log("获得评论");
			        console.log(res.data);
			        _this.setData({comments:res.data});
			      }
			    })
		4)在页面中使用wx.for对数组进行绑定
			 <view wx:for="{{comments}}" wx:for-item="comment">
				  <view>{{comment.time}}</view>
				  <view>{{comment.username}}</view>
				  <view>{{comment.content}}</view>
				  <image style="width:12px;height:12px" wx:for="{{comment.stars}}" src="../images/star1.png"></image>
				</view>

工作经历绑定

后台:
1)确定SQL语句
SELECT w.begin_date,w.end_date,w.work_place,t.work_type_name
FROM tb_work w,tb_work_type t
WHERE t.work_type_id = w.work_type_id AND w.nanny_id = 1;
2)编写实体类
参照SQL语句中的字段
3)编写Dao和其中的方法
public class WorkDaoImpl implements WorkDao{
@Override
public List findAllWorkByNannyId(int nannyId) {
return JdbcUtils.queryList(Work.class,
"SELECT w.begin_date,w.end_date,w.work_place,t.work_type_name "+
“FROM tb_work w,tb_work_type t “+
“WHERE t.work_type_id = w.work_type_id AND w.nanny_id = ?”, nannyId );
}
}
4)测试
5)编写Servlet
@WebServlet(”/findWorks.do”)
public class FindAllWorksByNannyId extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int nannyId = Integer.parseInt(req.getParameter(“nannyId”));
WorkDao dao = new WorkDaoImpl();
List works = dao.findAllWorkByNannyId(nannyId);
System.out.println(works);
//将集合转换为JSON数组发送给浏览器
String json = new Gson().toJson(works);
resp.setContentType(“text/html;charset=UTF-8”);
resp.getWriter().print(json);
}
}
6)测试

前端:
1)在data里定义评论数组变量
//用于绑定工作经历的数组变量
works:null
2)在onload中使用wx.request请求后台Servlet
3)在success使用setData给数组变量赋值
var _this = this;
wx.request({
url: ‘http://localhost:8080/MyNanny/findWorks.do?nannyId=’ + nanny2.nanny_id,
success(res) {
console.log(“获得评论”);
console.log(res.data);
_this.setData({ works: res.data });
},
})
4)在页面中使用wx:for对数组进行绑定
工作经历

工作时间:{{work.begin_date}}至{{work.end_date}}
工作地点:{{work.work_place}}
工作类型:{{work.work_type_name}}
联系前雇主

![在这里插入图片描述](https://img-blog.csdnimg.cn/20190821223109862.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MTYyMjgx,size_16,color_FFFFFF,t_70)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值