发表于: 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包下了。此时就会有上述错误报出。



时间都去哪了?

0840-0900洗漱

0900-0930吃饭

0930-0955tiles框架

1000-1050听志荣进复盘项目评审

1100-1200继续搭框架

1200-1230吃饭

1253-1351睡觉

1355-1720设计数据库,在项目里添加t11的内容

1720-1750下载IDEA控制台log4j输出颜色插件,网很坑下载巨慢。安装后找报错很方便

1756-1806bug

1810-1912吃饭

1915-2100解决bug

2110-2150弄前端页面。。。。想着后端代码写完了,跑起来看下效果,怎么弄都出不来

2200-2300看打tag标签

2330-2400休息

0000-0100整理日报

01:30-睡觉







返回列表 返回列表
评论

    分享到