电商实习项目第五天(6月28日)

  • select now() 数据库中获取时间

  • @ResponseBody//(返回ajax数据的注解_必须加)

  • 项目组成

项目组成
src——java源代码
包名是: 域名的反写——com.baidu.tieba(产品).www.po(分包名)					                                    
JRE
JAVAEE
JSTL
webroot——静态资源

  • MVC设计模式代码要分层———

Model数据模型———PO Dao

View显示———jsp

Controller控制———Action

(业务层)———Service

  • Servlet

表单请求:

post请求(用户名密码加密过);请求发数据无大小限制

get请求发数据有大小限制

servlet的两个方法请求转发和重定向的区别:

String s=request.getParameter("id");//查数据
//请求转发_请求转发——发到另一个jsp/ html页面——————index.jsp——用户发请求test.jsp, 服务器中调用index.jsp,将index.jsp页面发给用户

request.setAttribute("data",s);
request.getRequestDispatcher("index/jsp").forward(request,response);
//好处: 接收到的参数在新的jsp页面好用
//jsp页面:  ${data}可以得到data


//重定向——响应对象,访问jsp——业务层代码,登陆到首页(response对象)——用户发请求test.jsp, 服务器中跳转index.jsp,用户发送index.jsp请求,服务器拿到index.jsp发回给用户
request.setAttribute("data",s);//无用
response.sendRedirect("index.jsp")
//jsp获取不到data
  • 接口只可以定义: 静态常量(static)和 虚方法( 方法没有方法体 {})的集合
( public static final )静态常量  int a=1;
public  (abstruct )void getA();
  • 类 —— 必须实现接口中的全部方法

子类可以自己添加方法: private

  • Java中的List用法 :
List<Integer> list=new ArrayList<Integer>();
Integer b=new Integer(102);
//增
list.add(10);
list.add(11);
list.add(0);
list.add(0);
list.add(3,5);
system.out.println("list元素个数"+list.size());
//删
list.remove(4);
list.remove(b);
//改
//list.set(1,10);
//查
int pos=list.Indexof(b);
system.out.println(pos);
system.out.println("索引是2的元素"+list.get(2));
//遍历方法一:
for(Integer a: list){
    System.out.println(a);
}
//遍历方法二:
for(int i=0;i<list.size();i++)
{	 System.out.println(list.get(i)); 
}
//遍历方法三:
Iterator<Integer> it=list.iterator();
while(it.hasNext()){
    System.out.println(it.next());
}


  • Java中的Map用法:
Map<key类型,value类型>  //键值对
//Map没有顺序,能存一一对应关系,
Map<String,Integer> map=new HashMap<String,Integer>();
//增
map.put("s0001",100);
//改
map.put("s0001",102);//102覆盖100
map.put("a0001",103);   
system.out.println(map.size());//2个
//删
map.remove("s0002")
//遍历方法一:
map.get("s0001");
//遍历方法二:
Set<String> s= map.keySet();
for(String tmp:s)
{
    System.out.println(map.get(tmp));
}

发布了192 篇原创文章 · 获赞 204 · 访问量 42万+

猜你喜欢

转载自blog.csdn.net/qq_37486501/article/details/94012327