电商项目1

先写service 层,再写controller层。找到controller对应的service层,注入对应的service,然后传递参数、调用其中的方法即可。

写Service层接口时,如果没想清楚返回值,看看前端需要什么类型或者直接返回BaseResult。

什么时候返回逻辑视图,什么时候返回json数据?如果请求的是一个jsp页面,就返回逻辑视图;否则就返回一个json字符串。

Jvm调优,tomcat调优,修改里面的配置参数,但要理解每个参数的意思。

单表查询,使用逆向工程代码即可;一般mapper层都不需要写。

不就点sql语句吗?有什么难的。

开发语言与软件架构:语言应该不是重点发展吧,架构才是需要深入探讨的。语言只是工具,学好一门语言后学其他的都很快的。编程还是要深度发展的(软件架构)。程序员替代性很强(如何成为不可或缺的人?软件架构)。

数据库驱动包主要用于连接mysql数据库,访问数据库。 com.mysql.jdbc.Driver。

控制台输出中文乱码问题的解决,在Tomcat配置的时候,添加上 -Dfile.encoding=UTF-8。Tomcat配置的时候解决。

Idea中添加jar包与添加依赖的区别是什么?

如果是添加maven依赖,需要在pom.xml中进行配置,但是如果是添加jar包,就不需要进行配置,lib中选中jar单击as library。

如何停止Tomcat服务器的运行? 在Idea中的run面板,点击左侧的红色按钮就可以。

如何让Tomcat支持热部署? 对Tomcat进行配置,设置On 'update' action选项和下面的一个选项,当发现更新操作时,更新资源文件和class文件。自动编译 自动部署的功能。

Maven项目的标准结构

tomcat部署时war和war exploded区别?打成war包,发布模式。部署模式或者说开发模式。

在项目里,如果类名称有红点,不能编译运行。设置把当前文件夹当做源代码文件夹。

 

Controller层常用的注解

@RequestMappingg(value = "/save",method = RequestMethod.POST) 处理器映射器,把网络请求映射到对应的Controller。每个参数都要写完整,别省略。

@ResponseBody

@RequestParam(value = "id", defaultValue = "0") long parentId

@Autowired

@Controller

@Component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)

Controller层的请求参数,看看前端传递的是什么类型?如果是接收表单提交,那么就写成pojo类型;如果是图片,需要Multipart类型,其他的可以写成简单数据类型。

 

selectByPrimaryKey() 通过主键id进行查询,parentId在id列也是唯一的值。

什么时候使用insert()方法,什么时候使用update方法()?插入数据还是更新,想清楚业务逻辑?

id是自增张的,可以不用处理。

TbContentCategory selectByPrimaryKey(@Param("parentId") Long id);给方法参数命名,名称就是括号中的值

断点调试:看看哪里报了错误?特别好用,刚自己就调试出来了。

Date类的使用:new Date() 对应的是数据库中的年月日时分秒。

 

Cms内容管理系統:根据id查询商品功能。

Id自动增长,可以不用处理,特别是插入数据的时候。

如何实现主键返回功能,这是一个常用的功能点。什么时候需要主键返回?主键是数据库中主动生成的,例如主键是自增长的。如果业务层需要得到记录的主键(自增长)时,可以通过配置的方式来完成这个功能。

返回的数据结果data,里面有哪些字段,不能随便取值。If(data.status==200){ }

调试出来的错误:遇到问题,自己先调试一下,看看哪里报错了。

org.mybatis.spring.MyBatisSystemException:nested exception is

org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [parentId, param1]

 

Cms内容管理系統:需要一个内容分类表和一个内容表。内容分类和内容表是一对多的关系。

内容分类表,需要存储树形结构的数据。内容分类表:tb_content_category。内容表:tb_content

主要用来维护内容信息和内容分类信息。

 

Maven中的点:

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>dubbo</artifactId>

<!-- 排除依赖,依赖会进行传递 -->

<exclusions>

<exclusion>

<groupId>org.springframework</groupId>

<artifactId>spring</artifactId>

</exclusion>

<exclusion>

<groupId>org.jboss.netty</groupId>

<artifactId>netty</artifactId>

</exclusion>

</exclusions>

</dependency>

jquery中ajax的请求。

jQuery ajax - serialize() 方法:序列化表单值,FirstName=Bill&LastName=Gates。

如果jsp页面提交的信息是表单信息,需要对表单进行序列表提交。

// ajax中post请求
var params = {"ids": ids};
$.post("/content/delete", params, function (data) {
    if (data.status == 200) {
        alert("删除内容成功!");
    }

});
// ajax中post请求
$.post("/content/delete", $("#contentAddForm").serialize(), function (data) {
    if (data.status == 200) {
        alert("删除内容成功!");
    }
});

//重命名分类名称
$.post("/content/category/update",{id:node.id,name:node.text});
    /**
     * 通过请求参数查询数据,请求参数的健名要知道,简单数据类型的查询。
     * 返回指定格式的json数据
     *
     * @param parentId
     * @return
     */
    @RequestMapping(value = "/category/list")
    @ResponseBody
    public List<EasyUITreeNode> getContentCategory(@RequestParam(value = "id", defaultValue = "0") long parentId) {
        List<EasyUITreeNode> contentCatList = contentCategoryService.getContentCatList(parentId);
        return contentCatList;
    }

package cn.e3mall.serverimpl;

import cn.e3mall.common.E3Result;
import cn.e3mall.mapper.TbContentCategoryMapper;
import cn.e3mall.pojo.EasyUITreeNode;
import cn.e3mall.pojo.TbContentCategory;
import cn.e3mall.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * describe:内容分类关系
 *
 * @author chenrushui
 * @date 2018/07/16
 */
@Service
public class ContentCategoryServiceImpl implements ContentCategoryService {
    
    @Autowired
    private TbContentCategoryMapper bContentCategoryMapper;

    @Override
    public List<EasyUITreeNode> getContentCatList(long parentId) {
        //查询内容分类列表
        List<TbContentCategory> tbContentCategories = bContentCategoryMapper.selectContentCatByParentId(parentId);
        //创建返回的List集合
        ArrayList<EasyUITreeNode> result = new ArrayList<>();
        for (TbContentCategory tbContentCategory : tbContentCategories) {
            EasyUITreeNode node = new EasyUITreeNode();
            node.setId(tbContentCategory.getId());
            node.setText(tbContentCategory.getName());
            //当前节点是否是父节点
            node.setState(tbContentCategory.getIsParent() ? "closed" : "open");
            result.add(node);
        }
        return result;
    }

    /**
     * 添加新的内容分类
     *
     * @param parentId
     * @param name
     * @return
     */
    @Override
    public E3Result addContentCategory(long parentId, String name) {
        //创建一个pojo,因为inset()方法需要
        TbContentCategory tbContentCategory = new TbContentCategory();
        //id自动增长,不用设置
        //tbContentCategory.setId();
        tbContentCategory.setCreated(new Date());
        tbContentCategory.setUpdated(new Date());
        //新插入元素,肯定是子节点
        tbContentCategory.setIsParent(false);
        tbContentCategory.setName(name);
        tbContentCategory.setParentId(parentId);
        tbContentCategory.setSortOrder(1);
        tbContentCategory.setStatus(1);
        //插入完成后,tbContentCategory的id属性上会有值,主键返回的。
        bContentCategoryMapper.insert(tbContentCategory);
        //判断当前元素是否是父节点?如果不是,把当前元素变成父节点,通过当前id选择元素?
        TbContentCategory tbContentCate = bContentCategoryMapper.selectByPrimaryKey(parentId);
        if (!tbContentCate.getIsParent()) {
            tbContentCate.setIsParent(true);
            //把数据更新到数据库
            bContentCategoryMapper.updateByPrimaryKey(tbContentCate);
        }
        return E3Result.ok(tbContentCategory);
        //selectByPrimaryKey() 通过主键id进行查询,parentId在id列也是唯一的值。
        //什么时候使用insert()方法,什么时候使用update方法()?插入数据还是更新,想清楚业务逻辑?
        //id是自增张的,可以不用处理。
        //TbContentCategory selectByPrimaryKey(@Param("parentId") Long id);给方法参数命名,名称就是括号中的值
        //断点调试:看看哪里报了错误?特别好用,刚自己就调试出来了。
        //Date类的使用:new Date() 对应的是数据库中的年月日时分秒。
        //为什么使用long类型而不是使用int类型,数据库中参数的类型为long类型。
    }
}

 /**
     * 添加新的内容
     *
     * @param tbContent
     * @return
     */
    @Override
    public E3Result addContent(TbContent tbContent) {
        //前端有些数据没有传递
        tbContent.setCreated(new Date());
        tbContent.setUpdated(new Date());
        tbContentMapper.insert(tbContent);
        return E3Result.ok();
    }



    <!--查询方法:判断传递过来的字段属性是否为空,而不是数据库中的parent_id字段-->
    <!--常用的数据类型在哪个数据包下java.lang.Long-->
    <select id="selectContentCatByParentId" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select * from tb_content_category where
        <if test="id != null">
            parent_id=#{id}
        </if>
    </select>

   <!--把pojo中的数据原封不动的插入数据,不判断是否非空-->
    <insert id="insert" parameterType="cn.e3mall.pojo.TbContentCategory">

        <!--  设置主键返回,插入语句以后执行selectKey这些sql-->
        <selectKey keyProperty="id" resultType="java.lang.Long" order="AFTER">
            /* 把获取的主键映射到pojo的id属性上,last_insert_id() mysql提供的方法*/
            select last_insert_id();
        </selectKey>
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into tb_content_category (id, parent_id, name,
        status, sort_order, is_parent,
        created, updated)
        values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
        #{status,jdbcType=INTEGER}, #{sortOrder,jdbcType=INTEGER}, #{isParent,jdbcType=BIT},
        #{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
    </insert>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值