一、学到了什么?
1.怎么做前后端分离?
这个前后端分离它是一种架构模式,也就是前端和后端并行开发然后再联调测试的一种模式,它有四大优势,一是为优质产品打造精益团队,也就是传说中的专业的人做专业的事;二是提升开发效率,并行开发;三是完美应对复杂多变的前端需求;四是增强代码可维护性。
在开发的过程中,后端可以使用一种叫postman的软件进行模拟测试,而前端则可以使用一种叫mock的技术进行模拟测试。
此时,很多人就可能有疑问了,前后端之间虽然是分离的,但是它们之间肯定是有联系的,怎么来实现这个联系的呢?关于这个前后端之间的通信问题,就涉及到跨域问题了,也就是浏览器的同源策略问题,关于这个同源策略如果感兴趣的可以自己去网上搜索看看了解一下,注意:因为跨域是浏览器针对ajax请求的一种限制,因此跨域不一定会有跨域问题,解决跨域问题的方案有三种: Jsonp-- json变种、nginx反向代理(部署)、cors。我这里是使用的cors。
首先说后端,在后端可以使用@CrossOrigin标签解决跨域问题,注意,spring的版本要升级到4.2.5及以上才能使用。
@Controller
@RequestMapping("/customer")
@CrossOrigin
public class CustomerController {
@Autowired
private ICustomerService customerService;
@RequestMapping(value="/list",method = RequestMethod.PATCH)
@ResponseBody
public List<Customer> list(){
return customerService.findAll();
}
/*分页查询*/
@RequestMapping(value="/page",method= RequestMethod.PATCH)
@ResponseBody
@CrossOrigin
public PageList<Customer> page(@RequestBody CustomerQuery customerQuery){
PageList<Customer> pageList = customerService.findPage(customerQuery);
return pageList;
}
// 新增
@RequestMapping(value = "/save", method = RequestMethod.PUT)
@ResponseBody
public AjaxResult add(@RequestBody Customer customer) throws ParseException {
customerService.save(customer);
return new AjaxResult();
}
//修改
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public AjaxResult update(@RequestBody Customer customer){
customerService.update(customer);
return new AjaxResult();
}
// 删除
@RequestMapping(value="/delete/{id}",method = RequestMethod.DELETE)
@ResponseBody
public AjaxResult delete(@PathVariable Long id){
customerService.delete(id);
return new AjaxResult();
}
// 批量删除
@RequestMapping(value="/batchRemove",method = RequestMethod.POST)
@ResponseBody
@CrossOrigin
public AjaxResult batchRemove(@RequestBody Map<String,Object> para){
// 获取传回来的id字符串
String ids = para.get("ids").toString();
// 通过逗号分割字符串,获得所有的id
String[] id = ids.split(",");
for (String s : id) {
customerService.delete(s);
}
return new AjaxResult();
}
}
在前端,通过axios进行跨域访问,通常可以把axios理解为ajax的升级版。
import axios from 'axios'
//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost/';
//全局属性配置,在任意组件内可以使用this.$http获取axios对象
Vue.prototype.$http = axios;
注意:在此之前,必须要在main.js这个文件里面注释掉有关mock的一切信息。
import axios from 'axios'
//配置axios的全局基本路径
axios.defaults.baseURL='http://localhost/';
//全局属性配置,在任意组件内可以使用this.$http获取axios对象
Vue.prototype.$http = axios;
2.对svn的使用更加熟练。
3.对前端的基本crud更加熟悉。
4.对elementUI、vue的理解和使用。
5.初次使用maven多模式开发,每个模块的分工更加明确,进一步提高了代码的可读性和可维护性
6.初步接触到类似于企业的团队开发模式。
7.在这次项目中,我主要是做的客户管理这一块,在做这一块的时候,我主要做了两大问题的思考,首先思考的是与该模块相关的表与表之间的关系,以期达到更方便地做增删查改的sql语句编写和维护;其次思考的是前端与后端交互时的传参问题,其实主要是前端怎么把参数传递到后端和后端怎么接收参数的问题。令我收获颇多。
8.新了解到几个http状态码:403(http请求被拒绝访问资源)、400(前端参数传值问题)、405。
这里附上http常用对照表(包含http状态码对照表):https://tool.oschina.net/commons?type=5
9.全文检索lucene
不过相对Lucene来说,我更喜欢用ElasticSearch。
10.SaaS模式
软件即服务 各个租户在平台购买服务,享用服务