公司须要开发一个小程序,小程序也算是一个新兴技术,就本身研究了一下,总结了一些开发过程须要注意的事项,供你们参考。html
“无 AppID”,没法在真机上调试代码,但不影响开发。html5
开发时是为了方便调试,须要调用本地接口,能够参考另外一篇博客;java
在小程序中使用<map>须要获取位置经纬度,能够在腾讯坐标拾取器中获取;web
1 var that = this; 2 var timer = setInterval(function(){ 3 progressNum++; 4 if(progressNum >= 100){ 5 clearInterval(timer) 6 }; 7 that.setData({ 8 progress:progressNum 9 }); 10 },30)
存储输入值
spring
1 wx.setStorageSync('storage', this.data.storage)
从存储中获得数据
json
1 var that; 2 Page( { 3 data: { 4 storage:'' 5 }, 6 onLoad: function(options) { 7 that = this; 8 //获取存储信息 9 wx.getStorage({ 10 key: 'storage', 11 success: function(res){ 12 // success 13 that.setData({ 14 storage:res.data 15 }) 16 } 17 }) 18 } 19 20 })
微信小程序端小程序
chooseImage(){ wx.chooseImage({ success: function (res) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://127.0.0.1:8888/pesss/weChat/uploadImage.do', filePath: tempFilePaths[0], name: 'file', formData: { 'user': 'test' }, success: function (res) { var data = res.data //do something },fail:function(err){ console.log(err) } }) } }) }
java端微信小程序
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; @Controller public class ImageTestWebchatController { @RequestMapping(value = "/weChat/uploadImage", method = { RequestMethod.POST,RequestMethod.GET}) public ModelAndView uploadImage(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入get方法!"); MultipartHttpServletRequest req =(MultipartHttpServletRequest)request; MultipartFile multipartFile = req.getFile("file"); String realPath = "F:/image"; try { File dir = new File(realPath); if (!dir.exists()) { dir.mkdir(); } File file = new File(realPath,new Date().getTime() + ".jpg"); multipartFile.transferTo(file); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } return null; } }