发表于: 2017-06-23 23:02:19
3 1179
今日完成:
完成任务四用tiles框架实现页面10、11
使用tag转换时间
明日计划:
添加登录注册模块,并对用户是否登陆进行判断
收获:
什么是tiles框架?
把页面分成Header,Footer,Menu,Body,然后再用Templat模板拼装起来实现页面的复用。
为什么用tiles?
可重用性:基本界面可以被重用,组合成各种不同的复合式界面
可维护性:每个基本界面之间相互独立,当复合式界面中的局部区域发生变化,不会影响其它区域
可扩展性:可以方便的扩展基本界面。
总之就是维护方便,修改简单,各种拼凑。
需要掌握C标签,EL表达式技能。
tag标签转换时间
在jsp页面中需要显示日期时间格式,而数据库里存储的是long型的时间戳,比如1490715599560,我们需要在页面显示为2017-03-28 23:39:59 所以需要转换下日期格式才能正确显示
转换步骤:
1.写一个类继承TagSupport
public class DataTag extends TagSupport {
public int doStartTag() throws JspException {
String vv = "" + value;
long time = Long.valueOf((vv.trim()));
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time);
//转换为datePattern时间类型
SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
String s = dateFormat.format(c.getTime());
try {
pageContext.getOut().write(s);
} catch (IOException e) {
e.printStackTrace();
}
return super.doStartTag();
}
private String value;
public String datePattern;
2.在WEB-INF下面创建tld/datetag.tld
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>dateTag</short-name>
<description>simple hello tags tag</description>
<tag>
<name>dateTag</name>
<tag-class >com.ptteng.util.DataTag</tag-class >
<body-content>JSP</body-content>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>datePattern</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
3.在web.xml中引入
<!--tag标签引用-->
<jsp-config>
<taglib>
<taglib-uri>/tags</taglib-uri>
<taglib-location>/WEB-INF/tld/datetag.tld</taglib-location>
</taglib>
</jsp-config>
4.写一controller用于返回到一个jsp页面
@Controller
@RequestMapping
public class timeController {
@Autowired
private excellence_stuService service;
@RequestMapping(value = "/time/{id}",method = RequestMethod.GET)
public ModelAndView getTime(@PathVariable("id")int id) {
Long l = System.currentTimeMillis();
System.out.println(l);
excellence_stu stu = service.getTime(id);
ModelAndView mav = new ModelAndView("time");
mav.addObject("show", stu);
return mav;
5.在jsp页面中添加
<%@ taglib uri="/tags" prefix="date"%>
<date:dateTag value ="${show.create_at}" datePattern="yyyy-MM-dd hh:mm:ss" />
最后运行页面显示:
问题:
1.数据库建表时,字段的长度怎么确定,还是说用默认值?
2.发现别人的项目配置文件分的很细,比如Spring.xml mybatis.xml,spirngMVC.xml 而我喜欢把配置文件整合到一块儿,在项目开发中这样写,有问题吗?
3.怎样才能在建表时插入bigint类型的时间戳,目前我都是先给个空值,再去java代码中实现后,拷贝过来。百度没找到解决方法
4.报错:2017-06-23 18:01:04,980 [main] ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [/Users/shun/Desktop/javaTask/Task04/target/classes/spring-mvc.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'excellence_stuServiceImpl' for bean class [com.ptteng.service.impl.excellence_stuServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ptteng.service.excellence_stuServiceImpl]
这个问题找了好久,我用的IDEA最后clean install解决了,原因是我在A包下创建了AA类,然后我将AA类又移动到B包下了。此时就会有上述错误报出。
时间都去哪了?
08:40-09:00洗漱
09:00-09:30吃饭
09:30-09:55搭tiles框架
10:00-10:50听志荣进复盘项目评审
11:00-12:00继续搭框架
12:00-12:30吃饭
12:53-13:51睡觉
13:55-17:20设计数据库,在项目里添加t11的内容
17:20-17:50下载IDEA控制台log4j输出颜色插件,网很坑下载巨慢。安装后找报错很方便
17:56-18:06找bug
18:10-19:12吃饭
19:15-21:00解决bug
21:10-21:50弄前端页面。。。。想着后端代码写完了,跑起来看下效果,怎么弄都出不来
22:00-23:00看打tag标签
23:30-24:00休息
00:00-01:00整理日报
评论