java笔记
一、Controller
@Controller
@RequestMapping(value="department")
@Autowired
DepartmentService departmentService;
@RequestMapping(value = "doSave", method = {RequestMethod.POST, RequestMethod.GET})
@ResponseBody
public class DepartmentController extends BaseSpringController{
public AjaxJson save(@RequestBody Department department){
AjaxJson result = new AjaxJson();
logger.info("日程"+GsonUtil.toJson(department));
try{
String departmentId= schedule.getDepartmentId();
if(!CheckUtil.isNull(department)){
for(Department info : Department.getDepartments()){
info .setDepartmentId(departmentId);
info.setCreateDate(Calendar.getInstance().getTime());
info.setModifiedDate(Calendar.getInstance().getTime());
departmentService.createDepartment(info);
}
result.setSuccess(true);
result.setObj(departmentId);
}else{
logger.info("日程分享数据为空");
result.setSuccess(false);
result.setMsg("数据为空");
}
}catch(Exception e) {
logger.error(message:"异常",e);
result.setSuccess(false);
result.setMsg("数据异常")
}
}
}
public class Department{
private String departmentId;
private List<Department> departments;
public String getDepartmentId(){
return departmentId;
}
public void setDepartmentId(){
this.departmentId = departmentId;
}
public List<Department>getDepartments(){
return departments
}
public void setSchedules(List<Department> departments) {
this.departments= departments;
}
}
service
接口
public interface DepartmentService{
void createDepartment(Department department);
}
接口实现
@service
public class departmentServiceImpl implements ISdepartmentService{
@Autowired
DepartmentMapper departmentMapper ;
@Override
@Transactional(rollbackFor = Exception.class)
public void createDepartment(Department department){
departmentMapper.insert(department) ;
}
}
dao
public interface DepartmentMapper{
int insert(Department record)
}
xml
<mapper namespace="***model.DepartmentMapper" >
<insert id="insert" parameterType="***model.Department" >
insert into department()
values ()
</insert>
</mapper>