Skip to content

Commit 8803706

Browse files
committed
新增2个表和对应的实体、Mapper
1 parent 0fdc295 commit 8803706

File tree

14 files changed

+693
-52
lines changed

14 files changed

+693
-52
lines changed

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@
4545
<artifactId>mysql-connector-java</artifactId>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>com.fasterxml.jackson.core</groupId>
50+
<artifactId>jackson-core</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.fasterxml.jackson.core</groupId>
54+
<artifactId>jackson-databind</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.fasterxml.jackson.datatype</groupId>
58+
<artifactId>jackson-datatype-joda</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.fasterxml.jackson.module</groupId>
62+
<artifactId>jackson-module-parameter-names</artifactId>
63+
</dependency>
64+
4865
<dependency>
4966
<groupId>com.alibaba</groupId>
5067
<artifactId>druid</artifactId>

src/main/java/tk/mybatis/springboot/conf/WebMvcConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424

2525
package tk.mybatis.springboot.conf;
2626

27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.context.annotation.Bean;
2729
import org.springframework.context.annotation.Configuration;
2830
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
31+
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
2932
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
33+
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
34+
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
35+
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
36+
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
37+
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
3038

3139
/**
3240
* @author liuzh_3nofxnp
@@ -40,4 +48,16 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
4048
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
4149
}
4250

51+
// @Override
52+
// public void configureViewResolvers(ViewResolverRegistry registry) {
53+
// registry.enableContentNegotiation(new MappingJackson2JsonView());
54+
// registry.freeMarker().cache(false);
55+
// }
56+
//
57+
// @Bean
58+
// public FreeMarkerConfigurer freeMarkerConfigurer() {
59+
// FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
60+
// configurer.setTemplateLoaderPath("/WEB-INF/");
61+
// return configurer;
62+
// }
4363
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2016 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package tk.mybatis.springboot.controller;
26+
27+
import com.github.pagehelper.PageInfo;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.stereotype.Controller;
30+
import org.springframework.ui.ModelMap;
31+
import org.springframework.web.bind.annotation.*;
32+
import org.springframework.web.servlet.ModelAndView;
33+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
34+
import tk.mybatis.springboot.model.City;
35+
import tk.mybatis.springboot.service.CityService;
36+
37+
import java.util.List;
38+
39+
/**
40+
* @author liuzh
41+
* @since 2015-12-19 11:10
42+
*/
43+
@RestController
44+
@RequestMapping("/cities")
45+
public class CityController {
46+
47+
@Autowired
48+
private CityService cityService;
49+
50+
@RequestMapping
51+
public PageInfo<City> getAll(City city) {
52+
List<City> countryList = cityService.getAll(city);
53+
return new PageInfo<City>(countryList);
54+
}
55+
56+
@RequestMapping(value = "/add")
57+
public City add() {
58+
return new City();
59+
}
60+
61+
@RequestMapping(value = "/view/{id}")
62+
public City view(@PathVariable Integer id) {
63+
ModelAndView result = new ModelAndView();
64+
City city = cityService.getById(id);
65+
return city;
66+
}
67+
68+
@RequestMapping(value = "/delete/{id}")
69+
public ModelMap delete(@PathVariable Integer id) {
70+
ModelMap result = new ModelMap();
71+
cityService.deleteById(id);
72+
result.put("msg", "删除成功!");
73+
return result;
74+
}
75+
76+
@RequestMapping(value = "/save", method = RequestMethod.POST)
77+
public ModelMap save(City city) {
78+
ModelMap result = new ModelMap();
79+
String msg = city.getId() == null ? "新增成功!" : "更新成功!";
80+
cityService.save(city);
81+
result.put("city", city);
82+
result.put("msg", msg);
83+
return result;
84+
}
85+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2016 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package tk.mybatis.springboot.controller;
26+
27+
import com.github.pagehelper.PageInfo;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.ui.ModelMap;
30+
import org.springframework.web.bind.annotation.PathVariable;
31+
import org.springframework.web.bind.annotation.RequestMapping;
32+
import org.springframework.web.bind.annotation.RequestMethod;
33+
import org.springframework.web.bind.annotation.RestController;
34+
import org.springframework.web.servlet.ModelAndView;
35+
import tk.mybatis.springboot.model.UserInfo;
36+
import tk.mybatis.springboot.service.UserInfoService;
37+
38+
import java.util.List;
39+
40+
/**
41+
* @author liuzh
42+
* @since 2015-12-19 11:10
43+
*/
44+
@RestController
45+
@RequestMapping("/users")
46+
public class UserInfoController {
47+
48+
@Autowired
49+
private UserInfoService userInfoService;
50+
51+
@RequestMapping
52+
public PageInfo<UserInfo> getAll(UserInfo userInfo) {
53+
List<UserInfo> userInfoList = userInfoService.getAll(userInfo);
54+
return new PageInfo<UserInfo>(userInfoList);
55+
}
56+
57+
@RequestMapping(value = "/add")
58+
public UserInfo add() {
59+
return new UserInfo();
60+
}
61+
62+
@RequestMapping(value = "/view/{id}")
63+
public UserInfo view(@PathVariable Integer id) {
64+
ModelAndView result = new ModelAndView();
65+
UserInfo userInfo = userInfoService.getById(id);
66+
return userInfo;
67+
}
68+
69+
@RequestMapping(value = "/delete/{id}")
70+
public ModelMap delete(@PathVariable Integer id) {
71+
ModelMap result = new ModelMap();
72+
userInfoService.deleteById(id);
73+
result.put("msg", "删除成功!");
74+
return result;
75+
}
76+
77+
@RequestMapping(value = "/save", method = RequestMethod.POST)
78+
public ModelMap save(UserInfo userInfo) {
79+
ModelMap result = new ModelMap();
80+
String msg = userInfo.getId() == null ? "新增成功!" : "更新成功!";
81+
userInfoService.save(userInfo);
82+
result.put("userInfo", userInfo);
83+
result.put("msg", msg);
84+
return result;
85+
}
86+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2016 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package tk.mybatis.springboot.mapper;
26+
27+
import tk.mybatis.springboot.model.City;
28+
import tk.mybatis.springboot.util.MyMapper;
29+
30+
/**
31+
* @author liuzh_3nofxnp
32+
* @since 2016-01-22 22:17
33+
*/
34+
public interface CityMapper extends MyMapper<City> {
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2016 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package tk.mybatis.springboot.mapper;
26+
27+
import tk.mybatis.springboot.model.UserInfo;
28+
import tk.mybatis.springboot.util.MyMapper;
29+
30+
/**
31+
* @author liuzh_3nofxnp
32+
* @since 2016-01-22 22:17
33+
*/
34+
public interface UserInfoMapper extends MyMapper<UserInfo> {
35+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2014-2016 abel533@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package tk.mybatis.springboot.model;
26+
27+
import javax.persistence.*;
28+
29+
/**
30+
* 基础信息
31+
*
32+
* @author liuzh
33+
* @since 2016-01-31 21:42
34+
*/
35+
public class BaseEntity {
36+
@Id
37+
@Column(name = "Id")
38+
@GeneratedValue(strategy = GenerationType.IDENTITY)
39+
private Integer id;
40+
41+
@Transient
42+
private Integer page = 1;
43+
44+
@Transient
45+
private Integer rows = 10;
46+
47+
public Integer getId() {
48+
return id;
49+
}
50+
51+
public void setId(Integer id) {
52+
this.id = id;
53+
}
54+
55+
public Integer getPage() {
56+
return page;
57+
}
58+
59+
public void setPage(Integer page) {
60+
this.page = page;
61+
}
62+
63+
public Integer getRows() {
64+
return rows;
65+
}
66+
67+
public void setRows(Integer rows) {
68+
this.rows = rows;
69+
}
70+
}

0 commit comments

Comments
 (0)