@RestController
@RequestMapping("products")
public class ProductsController {
@Resource
private ProductsService ps;
@GetMapping
public Result select() throws Exception {
return new Result(ps.select(), null, "success", null);
}
@GetMapping("/{pId}")
public Result selectById(@PathVariable("pId")int pId) throws Exception{
return new Result(null,ps.selectById(pId),"success",null);
}
@PostMapping
public Result insert(@Validated Products products,BindingResult br) throws Exception {
if(br.hasErrors()) {
throw new ParamException();
}
ps.insert(products);
return new Result(null,null,"success",null);
}
@PutMapping
public Result updateById(@Validated Products products,BindingResult br) throws Exception {
System.out.println(products);
if(br.hasErrors()) {
throw new ParamException();
}
ps.updateById(products);
return new Result(null,null,"success",null);
}
@DeleteMapping("/{pId}")
public Result deleteById(@PathVariable("pId")int pId) throws Exception {
ps.deleteById(pId);
return new Result(null,null,"success",null);
}
}
(2)Service 层 ① Service 接口层 ProductsService 类
public interface ProductsService {
/**
*
Description:业务层查询所有数据的方法 </p>
*/
public List select() throws Exception;
/**
*
Description:业务层根据id查询数据的方法
*/
public Object selectById(int pId) throws Exception;
/**
*
Description: 业务层根据id更新数据的方法
*/
public void updateById(Products products) throws Exception;
/**
*
Description: 业务层新增数据的方法
*/
public void insert(Products products) throws Exception;
/**
*
Description: 业务层根据id删除数据的方法
*/
public void deleteById(int pId) throws Exception;
}
② Service 实现层 ProductsServiceImp 类
@Service
public class ProductsServiceImp implements ProductsService{
@Resource
private ProductsMapper mapper;
/*
*
Description:业务接口层查询所有数据的方法 </p>
*/
@Override
public List select() throws Exception {
return mapper.selectByExample(null);
}
/*
*
public class Result {
private List list; //集合封装
private Object object; //对象封装
private String code; //反馈信息
private String message; //显示错误信息
public Result() {}
public Result(List list, Object object, String code, String message) {
this.list = list;
this.object = object;
this.code = code;
this.message = message;
}
//省略set、get方法
}
(4)ProductsMapper 类,定义相关方法
public interface ProductsMapper {
int deleteByPrimaryKey(Integer pId);
int insert(Products record);
int insertSelective(Products record);
List selectByExample(ProductsExample example);
Products selectByPrimaryKey(Integer pId);
int updateByPrimaryKeySelective(Products record);
int updateByPrimaryKey(Products record);
}
(5)统一异常处理层 ① 自定义异常类
public class ParamException extends Exception{
}
② ExceptionResolver 类
@Component
public class ExceptionResolver implements HandlerExceptionResolver{
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception ex) {
FastJsonJsonView view = new FastJsonJsonView();
ex.printStackTrace();
Map map = new HashMap();
map.put("code", "error");
if(ex instanceof ParamException) {
map.put("message", "参数错误");
}else {
map.put("message", "服务器异常");
}
view.setAttributesMap(map);
ModelAndView mav = new ModelAndView();
mav.setView(view);
return mav;
}
}
系统中统计数据,由于调用统计过程,执行时间超过了weblogic设置的时间,提示如下错误:
统计数据出错!
原因:The transaction is no longer active - status: 'Rolling Back. [Reason=weblogic.transaction.internal
Totally five patchs committed to erlang otp, just small patchs.
IMO, erlang really is a interesting programming language, I really like its concurrency feature.
but the functional programming style
两个步骤:
1.用w命令找到要踢出的用户,比如下面:
[root@localhost ~]# w
18:16:55 up 39 days, 8:27, 3 users, load average: 0.03, 0.03, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
package edu.xidian.graph;
class MyStack {
private final int SIZE = 20;
private int[] st;
private int top;
public MyStack() {
st = new int[SIZE];
top = -1;
}
public void push(i