发表于: 2017-06-21 17:54:03
1 1025
今日完成:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin)
重新写了个web项目的增删改查操作
学习@RequestParam注解,@ModelAttribute注解
IDEA配置Jetty
使用postMan测试接口
学习log4j配置
明日计划:
学习Resin
编写启动,停止,重新部署脚本
使用top命令查看web服务占用内存和CPU
设计前端页面10,11数据库
收获:
@RequestParam是传递参数的
用于获取页面请求参数映射到处理方法的参数上
比如:访问一个URL:localhost:8080/**/?username=张三
需要传递一个参数,在controller中使用@RequestParam接收这个参数
目前发现只有在写登录注册时使用
@ModeAttribute有两种用法,常用的是第二种。
第一种:
放在方法上,访问Controller中任何一个请求处理方法前,SpringMvc先执行该方法,并将返回值以绑定对象为键添加到模型中
第二种:
运用在参数上,会将客户端传递过来的参数按名称注入到指定对象中,并且会将这个对象自动加入ModelMap中,便于View层使是绑定请求参数到命令对象。
举个栗子:
public String test(@ModelAttribute(“user”),它的作用是将该绑定的命令对象以“user”为名称添加到模型对象中供视图页面展示使用。我们此时可以在视图页面使用${user.username}来获取绑定的命令对象属性
在Controller中使用@ModeAttribute注解可以实现添加用户的的操作
使用@PathVariable注解可以实现根据id查询,删除,修改操作
下面是今天的成果,写了好久,总算有点眉目,可以自己敲出来了!!!
public class StudentController {
@Autowired
ServiceStudent service;
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add() {
return "Student/add";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(@ModelAttribute("stu") Student student) {
service.addStudent(student);
return "redirect:/list";
}
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
public String delete(@PathVariable("id") int id) {
int i = service.deleteStudent(id);
return "redirect:/list";
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, Model model) {
Student student = service.findStudentById(id);
model.addAttribute("update",student);
return "Student/update";
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id,Student stu) {
Student student = service.findStudentById(id);
student.setStu_name(stu.getStu_name());
student.setSign(stu.getSign());
student.setStu_school(stu.getStu_school());
student.setStu_introducer(stu.getStu_introducer());
service.updateStudent(student);
return "redirect:/list";
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String getAll(Model model) {
List<Student> list = service.getAllStudent();
model.addAttribute("list",list);
return "Student/list";
}
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getAll(HttpServletRequest request) {
List<Student> list = service.getAllStudent();
request.setAttribute("list", list);
return "Student/list";
}
@RequestMapping(value = "/list/{id}", method = RequestMethod.GET)
public String findStudentById(@PathVariable("id") int id, Model model) {
Student student = service.findStudentById(id);
model.addAttribute("show", student);
return "Student/show";
}
@RequestMapping(value = "/list/stu/{stu_name}", method = RequestMethod.GET)
public String findStudentByName(@PathVariable("stu_name") String stu_name, Model model) {
Student student = service.findStudentByName(stu_name);
model.addAttribute("show", student);
return "Student/show1";
}
IDEA配置jetty
1.设置项目路径
2.设置启动命令 jetty:run
3.设置端口-Djetty.port=8081
4.在Maven的pom.xml文件配置插件 加入如下👇代码
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.1.v20140609</version>
</plugin>
</plugins>
5.启动jetty,在postman输入接口url测试
Log4j由三个重要的组件构成:
日志信息的输出级别
ERROR、WARN、INFO、DEBUG
ERROR 为严重错误 主要是程序的错误
WARN 为一般警告,比如session丢失
INFO 为一般要显示的信息,比如登录登出
DEBUG 为程序的调试信息
日志信息的输出目的地
log4j.appender.appenderName = fully.qualified.name.of.appender.class
1.org.apache.log4j.ConsoleAppender(控制台)
2.org.apache.log4j.FileAppender(文件)
3.org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)
4.org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件)
5.org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
日志信息的输出格式
问题:
暂无?
时间都去哪了?
07:30-07:45洗漱
07:45-08:10吃饭
08:10-08:25总结昨日日报
08:30-09:45学习@RequestParam注解
09:45-11:40学习@ModelAttribute注解
11:50-12:30吃饭
12:30-13:40午睡
13:50-16:50在Controller里写增删改查
16:50-17:50整理知识点
18:10-18:43吃饭
18:50-19:30问韦琦师兄问题:怎么返回给前端json数据
19:30-19:50看老大知乎
20:00-22:10配置jetty使用postman测试接口
23:00-00:00发呆
00:10-01:00看了下日志的配置
01:30-08:20睡觉
评论