发表于: 2017-08-23 23:22:56
3 1050
今天完成的事情:使用了jetty 尝试了postman
数据库源更换了使用了db.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3360/mybatis
username=root
password=123123
#定义初始连接数
initialSize=0
#定义最大连接数
maxActive=20
#定义最大空闲
maxIdle=20
#定义最小空闲
minIdle=1
#定义最长等待时间
maxWait=60000
仿照写了controller
//标记这是一个控制器
@Controller
//所有的程序的第一接口
@RequestMapping("/task2")
public class HomeController {
private static Logger loggerController = Logger.getLogger(HomeController.class);
//自动配装StudentService
@Autowired
private StudentService studyService;
/*
* 对某个指定用户查询
* 链接为http://localhost:8081/task2/a/student/select/具体数据
*/
@RequestMapping(value="/a/student/select/{userId}",method = RequestMethod.GET)
public String detail(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable String userId) {
if(userId!=null) {
try {
loggerController.info("查找当前的用户信息");
loggerController.info("userId " + userId);
Student study = this.studyService.getUserId(userId);
loggerController.info("学生信息: "+ study);
//将数据绑定到model上,可以传入jsp页面
model.addAttribute("study", study);
} catch (Exception e) {
e.printStackTrace();
loggerController.error("查询失败" + e.getMessage());
return "common/errorJson";
}
return "student/studentDataliJson";
}
else {
loggerController.info("userId " + userId);
return "common/errorParameterJson";
}
}
/*
* 添加用户信息
* 链接为http://localhost:8081/task2/a/student/insert
* 格式为application/json
*/
@RequestMapping(value = "/a/student/insert",method = RequestMethod.POST)
public String insert(HttpServletRequest request, HttpServletResponse response, Model model,@RequestBody Student study ) {
//当没有输入userid时,提示传入参数出错
if (study.getUserId()!=null) {
try {
loggerController.info("添加用户信息");
int i = studyService.studyInsert(study);
loggerController.info("study :" + study);
loggerController.info("添加信息的行数" + i);
if(i == -1){
loggerController.info("用户信息已经存在");
return "error-data/errorDataExistsJson";
}
} catch (Exception e) {
e.printStackTrace();
loggerController.error("添加出错" + e.getMessage());
return "common/errorJson";
}
return "common/successJson";
}
else {
loggerController.info("study : " + study);
return "common/errorParameterJson";
}
}
/*
* 对用户名字进行修改,
* http://localhost:8081/task2/a/student/update
* 格式为application/x-www-form-urlencoded
*/
@RequestMapping(value = "/a/student/update",method = RequestMethod.PUT)
public String update(HttpServletRequest request, HttpServletResponse response,Model model, @RequestBody Student study){
//当没有输入userid时,提示传入参数出错
if(study.getUserId()!=null) {
try {
loggerController.info("修改用户信息");
loggerController.info("name : " + study.getName());
loggerController.info("userId : " + study.getUserId());
int i = studyService.studyUpdate(study);
loggerController.info("返回修改行数" + i);
if(i == -1){
loggerController.info("用户信息不存在");
return "error-data/errorDataExistsJson";
}
else {
loggerController.info("用户信息存在");
return "common/successJson";
}
} catch (Exception e) {
e.printStackTrace();
loggerController.error("修改出错" + e.getMessage());
return "common/errorJson";
}
}
else {
loggerController.info("userId : " + study.getUserId());
loggerController.info("name : " + study.getName());
return "common/errorParameterJson";
}
}
/*
* 删除用户信息
* http://localhost:8081/task2/a/student/delete/JAVA-4433
*/
@RequestMapping(value = "/a/student/delete/{userId}",method = RequestMethod.DELETE)
public String delete(HttpServletRequest request, HttpServletResponse response,Model model,@PathVariable("userId") String userId){
if (userId!= null) {
try {
loggerController.info("删除用户信息");
loggerController.info("userId : " + userId);
int i = studyService.studyDelete(userId);
loggerController.info("返回影响行数" + i);
} catch (Exception e) {
e.printStackTrace();
loggerController.error("" + e.getMessage());
return "common/errorJson";
}
return "common/successJson";
}
else {
loggerController.info("userId : " + userId);
return "common/errorParameterJson";
}
}
/*
* 查询表中所有用户信息
* http://localhost:8081/task2/a/student/all
*/
@RequestMapping(value = "/a/student/all",method = RequestMethod.GET)
public String all(HttpServletRequest request, HttpServletResponse response,Model model){
try {
loggerController.info("查询全部学生信息");
List<Student> study = studyService.studentAll();
loggerController.info("studylist : " + study);
int i = study.size();
loggerController.info("返回用户数量" + i);
model.addAttribute("study",study);
}catch(Exception e){
e.printStackTrace();
loggerController.error("查询错误" + e.getMessage());
return "common/errorJson";
}
return "student/studentListJson";
}
}
测试了相关接口 get 成功
明天计划的事情:继续重写相关的接口
遇到的问题:maven运行jetty时
版本问题 jdk不支持最新版的jetty 在依赖里面把jetty版本改成以前的就好了
一样是版本问题 把解压的文件夹里面的_metadate文件前面的_去掉就好了
收获:自己重画了mvc的流程 model view controller 感觉重点还是controller
看了看jsp的相关 很喜欢超链接
超链接是链接接网页间的桥梁 超链接的语法是:<a href = “url”>显示内容</a>
a:anchor锚 href:hyper reference 分为四类:
a.绝对地址:(适用于互联网上的绝对地址之间)也分为了两种
a)url http://
在Linux系统中路径用/表示,Windows中则是\(不建议使用,因为需要进行转义)
b)电子邮件 mailto: OWA(outlook web access) 表示在网页中发邮件
b.相对路径:(适用本网站的地址)在href后面跟其他网页名称及路径
c.书签索引:(适用于文本内的地址)d.图像超链接
但是没有ip的调用 不知道怎么跳转自己的页面了 只好跳转了baidu
评论