YONGFEIUALL

izheyi.com


  • Home

  • Archives

  • Categories

  • Tags

  • About

  • Search

Java项目实战 - JS跨域:jsonp

Posted on 2018-07-15 | In Java |

Jsonp

ajax请求受同源策略影响,不允许进行跨域请求,而script标签src属性中的链接却可以访问跨域的js脚本,利用这个特性,服务端不再返回JSON格式的数据,而是返回一段调用某个函数的js代码,在src中进行了调用,这样实现了跨域。

商品分类显示

通过这个例子来验证跨域请求。

Dao

逆向工程已经实现了Mapper,不需要再做修改。

Service

查询所有商品分类生成前台页面要求的json数据格式。返回一个pojo。
pojo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class CategoryNode {

public String name;
public String url;
public List<?> item;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public List<?> getItem() {
return item;
}
public void setItem(List<?> item) {
this.item = item;
}

}

and

1
2
3
4
5
6
7
8
9
10
11
12
public class CategoryResult {

public List<?> data;

public List<?> getData() {
return data;
}

public void setData(List<?> data) {
this.data = data;
}
}

接口类:

1
2
3
4
5
public interface ItemCategoryService {

CategoryResult getItemCategoryList();

}

实现类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@Service
public class ItemCategoryServiceImpl implements ItemCategoryService {

@Autowired
private TbItemCatMapper itemCatMapper;

public CategoryResult getItemCategoryList(){
CategoryResult result = new CategoryResult();
result.setData(getCatetoryList(0));

return result;
}

private List<?> getCatetoryList(long parentId){

TbItemCatExample example = new TbItemCatExample();
Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(parentId);

List<TbItemCat> list= itemCatMapper.selectByExample(example);

List resultList = new ArrayList<>();
//向list中添加节点
for (TbItemCat tbItemCat : list) {
//判断是否为父节点
if (tbItemCat.getIsParent()) {
CategoryNode catNode = new CategoryNode();
if (parentId == 0) {
catNode.setName("<a href='/products/"+tbItemCat.getId()+".html'>"+tbItemCat.getName()+"</a>");
} else {
catNode.setName(tbItemCat.getName());
}
catNode.setUrl("/products/"+tbItemCat.getId()+".html");
catNode.setItem(getCatetoryList(tbItemCat.getId()));

resultList.add(catNode);
//如果是叶子节点
} else {
resultList.add("/products/"+tbItemCat.getId()+".html|" + tbItemCat.getName());
}
}
return resultList;
}

}

Controller

接收页面传递过来的参数id。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Controller
public class ItemCategoryController {

@Autowired
private ItemCategoryService itemCategoryService;

@RequestMapping(value="/itemcat/list",
produces=MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String getItemCatList(String callback) {
CategoryResult catResult = itemCategoryService.getItemCategoryList();

//把pojo转换成字符串
String json = JsonUtils.objectToJson(catResult);
//拼装返回值
String result = callback + "(" + json + ");";
return result;
}
}

运行结果

Java项目实战 - 商品列表展示:with PageHelper

Posted on 2018-07-15 | In Java |

Mybatis - PageHelper

Mybatis的一个插件,PageHelper,非常方便mybatis分页查询。详细请参见:PageHelper

使用方法:

  1. 引入分页插件
  2. 配置拦截器插件
    在SqlMapConfig.xml中配置插件。
    1
    2
    3
    4
    5
    6
    7
    <!-- 配置分页插件 -->
    <plugins>
    <plugin interceptor="com.github.pagehelper.PageHelper">
    <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
    <property name="dialect" value="mysql"/>
    </plugin>
    </plugins>

Dao

逆向工程已经实现了Mapper,不需要再做修改。

Service

接收分页参数,一个是page一个是rows。
调用dao查询商品列表,返回一个EasyUIDataGrid支持的数据格式的商品列表。
pojo:
把它放到izheyi-manager-common里,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class EasyUiDataGridResult {

private long total;
private List<?> rows;
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public List<?> getRows() {
return rows;
}
public void setRows(List<?> rows) {
this.rows = rows;
}
}

接口类:

1
2
3
4
public interface ItemService {

EasyUiDataGridResult getItemList(int page, int rows);
}

实现类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@Service
public class ItemServiceImpl implements ItemService {

@Autowired
private TbItemMapper itemMapper;

@Override
public EasyUiDataGridResult getItemList(int page, int rows) {
//Search
TbItemExample example = new TbItemExample();
PageHelper.startPage(page, rows);//分页
List<TbItem> list = itemMapper.selectByExample(example);

//创建返回对象
EasyUiDataGridResult result = new EasyUiDataGridResult();
result.setRows(list);

//总条数
PageInfo<TbItem> pageInfo = new PageInfo<>(list);
result.setTotal(pageInfo.getTotal());

return result;
}
}

Controller

接收页面传递过来的参数page、rows。

1
2
3
4
5
6
7
8
9
10
11
12
13
@Controller
public class ItemController {

@Autowired
private ItemService itemService;

@RequestMapping("/item/list")
@ResponseBody
public EasyUiDataGridResult getItemList(int page, int rows){
EasyUiDataGridResult tbItem = itemService.getItemList(page, rows);
return tbItem;
}
}

运行结果

Java项目实战 - 打开后台管理页面

Posted on 2018-07-15 | In Java |

前提

需要把静态资源Copy到WEB-INF下。

在web.xml文件中定义的url拦截形式为“/”表示拦截所有的url请求,包括静态资源例如css、js等,需要在springmvc.xml中添加资源映射标签:

1
2
<mvc:resources location="/WEB-INF/js/" mapping="/js/**"/>
<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/>

实现

在izheyi-manager-web工程下src/main/main下添加Controller。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.izheyi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* This is for page controller
* @author yongfei.hu
*
*/

@Controller
public class PageController {


/*
* Open homepage
*/

@RequestMapping("/")
public String homePage(){

return "index";
}
/*
* Navigator to page
*/

@RequestMapping("/{page}")
public String goToPage(@PathVariable String page) {

return page;
}

}

运行打开页面:

Java项目实战 - SSM整合:表现层

Posted on 2018-07-14 | In Java |

springmvc.xml

在izheyi-manager-web工程下src/main/resources,该spring文件夹下创建配置文件——springmvc.xml,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


<!-- 掃描Controller -->
<context:component-scan base-package="com.izheyi.controller" />

<!-- 配置注解驱动 -->
<mvc:annotation-driven />

<!-- 配置视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- 资源映射 -->
<mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
<mvc:resources location="/WEB-INF/js/" mapping="/js/**" />

</beans>

web.xml

在izheyi-manager-web工程下src/main/webapp,该WEB-INF文件夹下创建配置文件——web.xml,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="taotao" version="2.5">

<display-name>taotao-manager</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 解决post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- springmvc的前端控制器 -->
<servlet>
<servlet-name>zheyi-manager</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>zheyi-manager</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

实现在服务层初始化spring容器

Java项目实战 - SSM整合:Service层

Posted on 2018-07-14 | In Java |

applicationContext-service.xml

在izheyi-manager-web工程下src/main/resources,该spring文件夹下创建配置文件——applicationContext-service.xml,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">


<!-- 扫描包加载Service实现类 -->
<context:component-scan base-package="com.izheyi.service"></context:component-scan>
</beans>

service一般是由接口和实现类组成

applicationContext-trans.xml

在izheyi-manager-web工程下src/main/resources,该spring文件夹下创建配置文件——applicationContext-trans.xml,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">


<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 切面 -->
<aop:config>
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* com.izheyi.service.*.*(..))" />

</aop:config>
</beans>

切面,也就是事务的作用范围

Java项目实战 - SSM整合:Dao层

Posted on 2018-07-14 | In Java |

SqlMapConfig.xml

在izheyi-manager-web工程下src/main/resources,创建文件夹mybatis;在该文件夹下创建Mybatis的配置文件——SqlMapConfig.xml,内容如下:

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

</configuration>

applicationContext-dao.xml

在izheyi-manager-web工程下src/main/resources,创建文件夹spring;在该文件夹下创建Dao的配置文件——applicationContext-dao.xml,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">


<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:properties/db.properties" />

<!-- 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">

<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="maxActive" value="10" />
<property name="minIdle" value="5" />
</bean>

<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文件 -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
</bean>

<!-- 扫描Mapper文件 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.izheyi.mapper" />
</bean>
</beans>

数据库的配置放到配置文件,要在src/main/resource下创建文件夹properties,在该文件夹下创建db.properties文件,内容如下:

1
2
3
4
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/zheyi?characterEncoding=utf-8
jdbc.username=root
jdbc.password=

Java项目实战 - SSM整合:思路

Posted on 2018-07-12 | In Java |

SSM框架是spring MVC ,spring和mybatis框架的整合,是标准的MVC模式,将整个系统划分为表现层,controller层,service层,DAO层四层

  • spring MVC负责请求的转发和视图管理
  • spring实现业务对象管理
  • mybatis作为数据对象的持久化引擎, mapper代理开发方式开发Dao

DataBase ===> Entity ===> Mapper.xml ===> Mapper.Java ===> Service.java ===> Controller.java ===> Jsp.

Dao层

mybatis整合spring,通过spring管理SqlSessionFactory、mapper代理对象。

  • SqlMapConfig.xml - Mybatis核心配置文件
  • applicationContext-dao.xml
    • 数据库连接池。
    • SqlSessionFactory对象。
    • 配置mapper文件扫描器。

      Service层

      所有的service实现类都要放到spring容器中管理。
  • applicationContext-service.xml文件中配置包扫描器,扫描带@service注解的类。
  • applicationContext-trans.xml文件中配置事务。

表现层

表现层就一个springmvc框架,由springmvc来管理controller。

  • 包扫描器,扫描带@Controller注解的类。
  • 配置注解驱动。
  • 配置视图解析器。

web.xml

  • 配置Spring容器
  • 配置前端控制器
  • 配置Post乱码过滤器

Java项目实战 - MyBatis及逆向工程

Posted on 2018-07-08 | In Java |

前提

先创建Mysql DB,并准备数据。

MyBatis

  • SqlMapConfig.xml,此文件作为mybatis的全局配置文件,配置了mybatis的运行环境等信息。mapper.xml文件即sql映射文件,文件中配置了操作数据库的sql语句,此文件需要在SqlMapConfig.xml中加载。
  • 通过mybatis环境等配置信息构造SqlSessionFactory(即会话工厂)。
  • 由会话工厂创建sqlSession即会话,操作数据库需要通过sqlSession进行。
  • mybatis底层自定义了Executor执行器接口操作数据库,Executor接口有两个实现,一个是基本执行器、一个是缓存执行器。
  • MappedStatement也是mybatis一个底层封装对象,它包装了mybatis配置信息及sql映射信息等。mapper.xml文件中一个sql对应一个MappedStatement对象,sql的id即是MappedStatement的id。
  • MappedStatement对sql执行输入参数进行定义,包括HashMap、基本类型、pojo,Executor通过MappedStatement在执行sql前将输入的java对象映射至sql中,输入参数映射就是JDBC编程中对preparedStatement设置参数。
  • MappedStatement对sql执行输出结果进行定义,包括HashMap、基本类型、pojo,Executor通过MappedStatement在执行sql后将输出结果映射至java对象中,输出结果映射过程相当于JDBC编程中对结果的解析处理过程。

逆向工程

generatorConfig.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">


<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/zheyi" userId="root"
password="">

</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->

<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.izheyi.pojo"
targetProject=".\src">

<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.izheyi.mapper"
targetProject=".\src">

<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.izheyi.mapper"
targetProject=".\src">

<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 -->
<table schema="" tableName="tb_content"></table>
<table schema="" tableName="tb_content_category"></table>
<table schema="" tableName="tb_item"></table>
<table schema="" tableName="tb_item_cat"></table>
<table schema="" tableName="tb_item_desc"></table>
<table schema="" tableName="tb_item_param"></table>
<table schema="" tableName="tb_item_param_item"></table>
<table schema="" tableName="tb_order"></table>
<table schema="" tableName="tb_order_item"></table>
<table schema="" tableName="tb_order_shipping"></table>
<table schema="" tableName="tb_user"></table>

</context>
</generatorConfiguration>

注意:逆向工程多次执行后,它不会把原来的文件覆盖,而是会在原来文件的内容里面再追加。 要再生成,要把已经生成的删除。

Java项目实战 - 环境搭建

Posted on 2018-07-08 | In Java |

通过一个Java项目实战,对Java开发框架和流程有个更细的认知和学习。

前提

  • JDK的安装配置
  • Tomcat的安装配置
    • 下载解压,运行tomcat目录中的bin/startup.bat,启动tomcat,启动后有浏览器输入http://localhost:8080/,验证安装。
  • Eclipse的配置
    • 默认字符集更改为utf-8
    • 添加Tomcat运行环境
    • 添加Tomcat Server

工程创建

Github: zheyi-taotao

Maven

3种打包方式:

  • jar
    jar工程,很显然就是pom工程的子工程,由pom工程来管理。
  • war
    war工程是一个web工程,是可以直接放到tomcat下运行的工程。
  • pom
    pom工程一般都是父工程,管理jar包的版本、maven插件的版本、统一的依赖管理,它是一个聚合工程。其实说白了它只有一个pom.xml文件,一般是作为父工程出现的,只是定义了一些依赖、插件、还有一些版本号等等

工程目录

  • zheyi-parent:父工程,其打包方式是pom,主要管理jar包的版本号。项目中的所有工程都应该继承父工程。
  • zheyi-common:存放一些通用的工具类、通用的pojo。其打包方式为jar,被其他的工程所依赖。
  • zheyi-manager:服务层工程,又称之为聚合工程或pom工程。
    • zheyi-manager-pojo:这是一个独立的模块,其打包方式是jar。
    • zheyi-manager-mapper:这是一个独立的模块,其打包方式是jar。
    • zheyi-manager-service:打包方式是jar。
    • zheyi-manager-web:表现层工程,打包方式是war。

运行

创建完成后,运行,如下图所示:

注意事项

  • 运行要先Install parent和common
  • pageHelper-3.4.2-fix couldn’t download, change to 5.0.1
  • 要在web下创建web.xml

莫辜负自己,做一个努力上进的同学

Posted on 2018-07-01 | In 随想 |

工作了这么多年,见到了各式各样的人,见过工作五六年就成总监的,也见过工作了十几年还是跟刚工作时基本一个样子的。偶尔在这种差别上会想很多,没有说要跟任何人去比较,每个人的追求和想要的状态都不一样,而是会想现在的自己有没有优于过去的自己,在这个快速发展且浮躁的社会,会不会被淘汰掉。

都说上学是三点一线,其实工作了,再加上外卖的盛行,就剩两点一线了,公司到家里。如果上班盼下班,周一盼周五,周末在家追剧,睡觉,玩游戏,得过且过,你这辈子可能也仅此而已。有梦想有目标的人,我想会找个能发挥自己最大价值的工作,并不断的提升自己,做出成绩。不要随波逐流,安于现状,没有梦想跟咸鱼有什么区别,来先定一个小目标,找一个自己适合且能体现价值的工作。

还有很多人说,老板给我这些钱和这个职位,我就干这些活,听着是合理的,拿多少钱办多少事。但你要想到你不是为公司打工,你是为自己,为你的发展而努力,你才是你自己的老板。你的竞争力是你能力的提升,是不可替代性,而不是你待了多长时间和重复的技能,能力是在不断的做挑战性的工作而得到提升。不要只看眼前的一亩三分地,要勇于挑战自己,抓住机会,要不然一旦有替代者出现,就会应了那句话:你可以不服,你可以委屈,但你被淘汰了。

你要试着让自己变得不可替代。罗胖说要变得更好就是要想清楚三件事:目标,方法和行动。跟我在精益思想里看的一模一样,里边也讲到了这个,怎样实现精益,并尽善尽美。人本质上是个懒惰的动物,一定要有不断的目标,给自己一个目标,其实就是给自己一个盼头,而这个盼头会让你变得不懒惰,会驱使着你不断的进取。

所以当你想做出改变的时候,当你想让自己变得更好的时候,或许前路布满荆棘,或许心里有恐慌和迷茫,但还是要勇敢的走出这一步,等你越过山丘,定会看到更美的风景和更好的自己。

1…111213…40
唐胡璐

唐胡璐

i just wanna live while i am alive

393 posts
42 categories
74 tags
RSS
LinkedIn Weibo GitHub E-Mail
Creative Commons
© 2022 唐胡璐
Powered by Hexo
|
Theme — NexT.Pisces v5.1.4