发表于: 2017-08-17 22:02:24
1 1118
今天完成的事情:
审核了任务一,师兄发现还有一些要改进的地方,于是增加了Service接口和ServiceImpl实现类,并测试,贴代码
public interface StudentService {
StudentMod studySelect(StudentMod studentMod);
int studyInsert(StudentMod studentMod);
int studyUpdate(StudentMod studentMod);
int studyDelete(String id);
List<StudentMod> studentName();
}
@Service("studentService")
public class StudentServiceImpl implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public StudentMod studySelect(StudentMod studentMod) {
StudentMod studentMod1 = studentMapper.studySelect(studentMod);
return studentMod1;
}
@Override
public int studyInsert(StudentMod studentMod) {
int i = studentMapper.studyInsert(studentMod);
return i;
}
@Override
public int studyUpdate(StudentMod studentMod) {
int i = studentMapper.studyUpdate(studentMod);
return i;
}
@Override
public int studyDelete(String id) {
int i = studentMapper.studyDelete(id);
return i;
}
@Override
public List<StudentMod> studentName() {
List<StudentMod> studentMods = studentMapper.studentName();
return studentMods;
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:ApplicationContext-druid.xml"})
public class Test1 {
@Autowired
ApplicationContext ctx;
@Test
public void studentDelete()throws Exception{
StudentServiceImpl studentService = (StudentServiceImpl) ctx.getBean("studentService");
studentService.studyDelete("26");
}
@Test
public void studentInsert(){
StudentServiceImpl studentService = (StudentServiceImpl) ctx.getBean("studentService");
StudentMod studentMod = new StudentMod();
Long date = System.currentTimeMillis();
studentMod.setName("123");
studentMod.setQq(222222);
studentMod.setType("java");
studentMod.setTime(20170816L);
studentMod.setSchool("beida");
studentMod.setNumber(1122);
studentMod.setLink("eee");
studentMod.setHope("tiantian");
studentMod.setReferrer("somebody");
studentMod.setFrom_where("123");
studentMod.setCreate_at(20170817L);
studentMod.setUpdate_at(date);
studentService.studyInsert(studentMod);
}
@Test
public void studentUpdate(){
StudentServiceImpl studentService = (StudentServiceImpl) ctx.getBean("studentService");
StudentMod studentMod = new StudentMod();
studentMod.setName("555");
studentMod.setUpdate_at(20170816L);
studentMod.setId(26);
studentService.studyUpdate(studentMod);
}
@Test
public void studentSelect(){
StudentServiceImpl studentService = (StudentServiceImpl) ctx.getBean("studentService");
StudentMod studentMod = new StudentMod();
studentMod.setName("123");
studentService.studySelect(studentMod);
System.out.println(studentMod);
}
这样一开始是运行不了的,报错找不到studentService这个Bean,明明用了@Service注解也自动装配了Mapper啊。
检查了一下发现配置文件里需要写上自动注入@Service这个东西
<context:component-scan base-package="com.springmybatis.service" />
运行就可以了。
任务一可以结束了,开始任务二。
简单看了一下RESTful API
网络应用程序分为前段,后端两个部分,需要一种统一的机制来方便前端与后端之间进行通信,这就导致API架构流行,其中RESTful API是很成熟的一套API理论。
Rest接口设计规范
URI:统一资源标识符
URL:统一资源定位符
URL是URI的一个子集。
我们使用分隔符“/”来对资源层级进行划分,并且为了避免混淆,“/”不应该出现在末尾。
URI中连字符“-”用来分割出现的字符串(单词),来提高URI的可读性。使用“_”来分割字符串(单词)与链接的样式冲突重叠。
URI中统一使用小写字母。但主机名(host)和scheme(协议名称)对大小写是不敏感的。
HTTP响应状态码的使用
200(“ok”)用于一般性成功返回
201(“Created”)资源被创建
202(“Accepted”)用于Controller控制类资源异步处理的返回,仅表示请求已经收到,对于耗时比较久的处理,一般用异步处理来完成
204(“No Content”)
301(“Moved Permanently”)
302(“Found”)
303(“See Other”)
304(“Not Modified”)
307(“Temporary Redirect”)
400(“Bad Request”)
401(“Unauthorized”)在访问一个需要验证的资源时,验证错误
403(“Forbidden”)
404(“Not Found”)找不到URI对应的资源
405(“Method Not Allowed”)
406(“Not Acceptable”)
409(“Conflict”)资源状态冲突,例如客户端尝试删除一个非空的Store资源
412(“Preconditioned Failed”)用于有条件的操作不被满足时
415(“Unsupported Media Type”)客户所支持的数据类型,服务端无法满足
500(“Internal Server Error”)服务器端的接口错误,此错误于客户端无关
明天计划的事情:
开始任务二,看一下SpringMVC
遇到的问题:
已解决
收获:REST接口风格的规范
进度:
任务二
任务开始时间:2017.8.18
预计demo时间:2017.8.22
是否有延期风险:无
禅道链接:http://task.ptteng.com/zentao/project-task-286.html
评论